{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# EARLY RIDERS ! "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "42140"
      ],
      "text/latex": [
       "42140"
      ],
      "text/markdown": [
       "42140"
      ],
      "text/plain": [
       "[1] 42140"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "\n",
    "import_and_maybe_install <- function(pkgs){\n",
    "    missing_packages <- character(0)\n",
    "    for(pkg in pkgs){\n",
    "        tryCatch({\n",
    "            require(pkg, character.only=TRUE ,quietly=TRUE)\n",
    "        },warning=function(err){\n",
    "            missing_packages <<- c(missing_packages,pkg)\n",
    "        })\n",
    "    }\n",
    "    if(length(missing_packages)){\n",
    "            install.packages(missing_packages)\n",
    "            sapply(missing_packages, require, character.only=TRUE,quietly=TRUE)\n",
    "    }\n",
    "    invisible(NULL)\n",
    "}\n",
    "import_and_maybe_install(c(\"data.table\", \"feather\", \"ggplot2\",\"clusterSEs\",\"formula.tools\",\"estimatr\",\"doAzureParallel\"))\n",
    "Sys.getpid()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "DATA_DIR <- \"~/connector/20200226/analytic_datasets\"\n",
    "\n",
    "commute_ride_data <- read_feather( file.path(DATA_DIR,\"commute_ride_data.feather\"))\n",
    "setDT(commute_ride_data)\n",
    "commute_ride_data[,I405HOV:=0 + (date > as.Date(\"2015-09-25\"))]\n",
    "\n",
    "# FACTOR VARIABLES\n",
    "stopifnot(commute_ride_data[,class(fAid) == \"factor\"]) # rider id\n",
    "stopifnot(commute_ride_data[,class(fDate) == \"factor\"]) # date id\n",
    "\n",
    "#route_field <- sprintf(\"route_%s_10_ride\",1:21)\n",
    "\n",
    "# CALCULATE FAVORITE ROUTE\n",
    "commute_ride_data$favorite_route <- apply(\n",
    "    as.matrix(commute_ride_data[,sprintf(\"route_%s_10_ride\",1:21),with=FALSE]),\n",
    "    1,\n",
    "    function(x){\n",
    "        routes = which(x == max(x))\n",
    "        if(length(routes) == 1){\n",
    "            routes\n",
    "        }else{\n",
    "            sample(routes,1)\n",
    "        }\n",
    "    })\n",
    "\n",
    "commute_ride_data[, f_favorite_route:= as.factor(favorite_route) ]\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### FILTER on EARLY RIDERS"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Number of Early Riders"
     ]
    },
    {
     "data": {
      "text/html": [
       "3908"
      ],
      "text/latex": [
       "3908"
      ],
      "text/markdown": [
       "3908"
      ],
      "text/plain": [
       "[1] 3908"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Full Data"
     ]
    },
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<thead><tr><th scope=col>Records</th><th scope=col>Rides</th></tr></thead>\n",
       "<tbody>\n",
       "\t<tr><td>3354470</td><td>805199 </td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "\\begin{tabular}{r|ll}\n",
       " Records & Rides\\\\\n",
       "\\hline\n",
       "\t 3354470 & 805199 \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "| Records | Rides |\n",
       "|---|---|\n",
       "| 3354470 | 805199  |\n",
       "\n"
      ],
      "text/plain": [
       "  Records Rides \n",
       "1 3354470 805199"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Early riders only"
     ]
    },
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<thead><tr><th scope=col>Records</th><th scope=col>Rides</th></tr></thead>\n",
       "<tbody>\n",
       "\t<tr><td>1792156</td><td>640522 </td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "\\begin{tabular}{r|ll}\n",
       " Records & Rides\\\\\n",
       "\\hline\n",
       "\t 1792156 & 640522 \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "| Records | Rides |\n",
       "|---|---|\n",
       "| 1792156 | 640522  |\n",
       "\n"
      ],
      "text/plain": [
       "  Records Rides \n",
       "1 1792156 640522"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "\n",
    "dates = commute_ride_data[,.N,keyby=.(date,fDate)]\n",
    "MAX_DATE = dates[15,date]\n",
    "\n",
    "early_riders = commute_ride_data[date <= MAX_DATE & did_ride,1,keyby=aid][,V1:=NULL]\n",
    "cat(\"Number of Early Riders\")\n",
    "early_riders[,.N]\n",
    "\n",
    "cat(\"Full Data\")\n",
    "commute_ride_data[,.(Records=.N,Rides=sum(did_ride))]\n",
    "\n",
    "setkey(commute_ride_data,aid)\n",
    "commute_ride_data = commute_ride_data[early_riders]\n",
    "\n",
    "cat(\"Early riders only\")\n",
    "commute_ride_data[,.(Records=.N,Rides=sum(did_ride))]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "================================================================================\n",
      "Batch Account: msftconnectorpaper\n",
      "Batch Account Url: https://msftconnectorpaper.westus2.batch.azure.com\n",
      "Storage Account: msftconnectorpaper\n",
      "Storage Account Url: https://msftconnectorpaper.blob.core.windows.net\n",
      "================================================================================\n",
      "Your credentials have been successfully set.\n",
      "================================================================================\n",
      "Name: msftconnectorpaper\n",
      "Configuration:\n",
      "\tDocker Image: rocker/tidyverse:3.4.1\n",
      "\tMaxTasksPerNode: 3\n",
      "\tNode Size: Standard_D13_v2\n",
      "cranPackages: \n",
      "\tdoParallel; data.table; feather; formula.tools; \n",
      "githubPackages: \n",
      "\tAzure/doAzureParallel; jdthorpe/clusterSEs; \n",
      "Scale:\n",
      "\tAutoscale Formula: QUEUE\n",
      "\tDedicated:\n",
      "\t\tMin: 0\n",
      "\t\tMax: 0\n",
      "\tLow Priority:\n",
      "\t\tMin: 62\n",
      "\t\tMax: 150\n",
      "================================================================================\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Warning message in self$client$extractAzureResponse(response, content):\n",
      "\"Conflict (HTTP 409).\"\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The specified cluster 'msftconnectorpaper' already exists. Cluster 'msftconnectorpaper' will be used.\n",
      "Your cluster has been registered.\n",
      "Dedicated Node Count: 0\n",
      "Low Priority Node Count: 62\n"
     ]
    }
   ],
   "source": [
    "setCredentials(\"Connector/creds.json\")\n",
    "cluster <- makeCluster(\"Connector/config.json\",wait=FALSE)\n",
    "registerDoAzureParallel(cluster)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "it's all good, there are 186 workers\n"
     ]
    }
   ],
   "source": [
    "n_workers <- getDoParWorkers()\n",
    "stopifnot(n_workers>0)\n",
    "cat(sprintf(\"it's all good, there are %s workers\\n\",n_workers))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Data Dictionary\n",
    "\n",
    "Each record represents one rider commute opportunty (rider / date / commute).\n",
    "\n",
    "**Note that** there is one record for each commute / data for every rider \n",
    "*After their first ride date*.  This is because the choice to ride (`did_ride`) \n",
    "is conditioned on the rider's history of riding, and which is not available \n",
    "on thier first ride.\n",
    "\n",
    "#### Identifiers\n",
    "* **aid**: Rider number (anonomyzed Numeric)\n",
    "* **fAid**: Rider number (anonomyzed Factor)\n",
    "* **date**: Date of the ride (as Date)\n",
    "* **fDate**: Date of the ride (as Factor)\n",
    "* **AfternoonId**: Function of Date, only true for Route 5\n",
    "\n",
    "#### Main outcome / predictor\n",
    "* **did_ride**: Did the rider ride on this date?\n",
    "* **imputed_new_buses**: The weighted average of the fraction of new busses \n",
    "     on the routes the rider took on the last (up to) 10 trips\n",
    "\n",
    "#### Time since last ride\n",
    "* **commutes_since_last_ride**: Number of commutes since rider's last ride (numeric; range 1 - 461)\n",
    "* **f_commutes_since_last_ride**: Number of commutes since rider's last ride (factor; range \"1\" - \"40+\")\n",
    "     \n",
    "#### Date based indicators\n",
    "* **SR520WBHOV**: SR 520 West Bound is open (Function of the date)\n",
    "* **SR520EBHOV**: SR 520 East Bound is open (Function of the date)\n",
    "* **I405HOV**: Is a 405 HOV is open (Function of the date )\n",
    "* **Route5Expansion**: Route 5 expanded (Function of Date )\n",
    "\n",
    "#### Features based on the rider's history\n",
    "* **route_X_10_ride** (e.g. `route_3_10_ride`):  Fraction of the rider's last 10 rides that were taken on route X\n",
    "* **is_peak_10_ride**: Fraction of the rider's last 10 rides that were taken **during peak traffic**\n",
    "* **IsESOther_10_ride**: Fraction of the rider's last 10 rides that were taken on **EastSide (other) routes**\n",
    "* **IsRouteSeattle_10_ride**: Fraction of the rider's last 10 rides that were taken on **Seattle Routes**\n",
    "* **Is405North_10_ride**: Fraction of the rider's last 10 rides that were taken on **I 405 North Routes**\n",
    "* **IsCoach_10_ride**: Fraction of the rider's last 10 rides that were taken on  **Coach (as opposed to shuttle) busses**\n",
    "* **first_stop_10_ride**: Fraction of the rider's last 10 rides that were taken from **the last AM stop**\n",
    "* **last_stop_10_ride**: Fraction of the rider's last 10 rides that were taken on  **the first AM stop**\n",
    "* **single_stop_10_ride**: Fraction of the rider's last 10 rides that were taken on **a Single Stop Route**\n",
    "* **vehicle_is_new_10_ride**: Fraction of the rider's last 10 rides that were taken on **a new vehicle**"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## A Handy Utility function for fitting models and gathering summary statistics"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "metadata": {},
   "outputs": [],
   "source": [
    "#' A cute little function for fitting a model and pulling out the headline statistics\n",
    "#'\n",
    "#' @param data A dataset for fitting the model\n",
    "#' @param model A number for identifying the model in a table (these second field in the \"coef\" output)\n",
    "#' @param lhs The left hand side of the model (as a string)\n",
    "#' @param predictors The effects of interested.  Specifically these are the effects that will be pulled out in the summary table\n",
    "#' @param adjust_for The fixed effects that will be included in the right hand side but not pulled out into the summar table\n",
    "#'\n",
    "#' @return A list containing the glm model (`$model`), and a matrix of interesting statistics from the\n",
    "#'       various models (`$coef`)\n",
    "\n",
    "fit_ridership_logit_models <- function(data,\n",
    "                                        model=1,\n",
    "                                        lhs=\"did_ride\",\n",
    "                                        predictors=\"new_fraction_10day\",\n",
    "                                        adjust_for=\"fDate\",# up to 231 levels\n",
    "                                        cluster_on = ~ f_favorite_route,\n",
    "                                        quick=FALSE,\n",
    "                                        seed = 10101,\n",
    "                                        boot.reps=1001,\n",
    "                                        granularity=\"\"){\n",
    "\n",
    "    begin = Sys.time()\n",
    "    cat(sprintf(\"Starting at %s\\n\",begin))\n",
    "    \n",
    "    # build and test the formula \n",
    "    (FMLA <- formula(paste(lhs,'~',paste(c(sort(adjust_for),sort(predictors)),collapse=' + '))))\n",
    "    (current_terms <- attr(terms(FMLA),\"term.labels\"))\n",
    "    \n",
    "    if(!all(predictors %in% current_terms)){\n",
    "        cat(sprintf(\"CURRENT TERMS: %s\\n\",current_terms))\n",
    "        cat(\"\\n\")\n",
    "        cat(sprintf(\"PREDICTORS: %s\\n\",predictors))\n",
    "        cat(\"\\n\")\n",
    "        \n",
    "        will_be_dropped <- setdiff(predictors,current_terms)\n",
    "        will_appear <- setdiff(current_terms,c(predictors,adjust_for))\n",
    "        stop(sprintf(\"The following terms will be are not robust to <<string parsing>>:\\n%s\\n\\nPlease Update them as follows:\\n%s\\n \",\n",
    "            paste0(will_be_dropped,collapse=\"\\n\"),\n",
    "            paste0(will_appear,collapse=\"\\n\")))\n",
    "    }\n",
    "    \n",
    "    UPDATED = update(FMLA,~.)\n",
    "    (updated_terms <- attr(terms(UPDATED),\"term.labels\"))\n",
    "    if(!(all(updated_terms %in% current_terms))){\n",
    "        \n",
    "        (will_be_dropped <- setdiff(current_terms,updated_terms))\n",
    "        (will_appear <- setdiff(updated_terms,current_terms))\n",
    "        \n",
    "        stop(sprintf(\"The following terms will be are not robust to <<model updates>>:\\n%s\\n\\nPlease Update them as follows:\\n%s\\n \",\n",
    "            paste0(will_be_dropped,collapse=\"\\n\"),\n",
    "            paste0(will_appear,collapse=\"\\n\")))\n",
    "    }\n",
    "    \n",
    "    quick_N <- 1e5\n",
    "    if(quick & data[,.N] > quick_N)\n",
    "        data <- data[sample(.N,quick_N)]\n",
    "\n",
    "    # FIT THE OLS MODELS\n",
    "\n",
    "    cat(sprintf(\"Starting the base glm (OLS) model...at %s\\n\",round(Sys.time() - begin,3)))\n",
    "    start <- Sys.time()\n",
    "    LM <- glm(FMLA, data = data) # required for the wild bootstrap\n",
    "\n",
    "    cat(sprintf(\"Finished the base glm (OLS) model... in %s seconds\\n\",round(Sys.time() - start,3)))\n",
    "\n",
    "    # SUMMARY OF THE OLS MODEL\n",
    "    cat(sprintf(\"Starting the summary()...at %s\\n\",round(Sys.time() - begin,3)))\n",
    "    start <- Sys.time()\n",
    "    cat(\"\\n===============================================\\n\")\n",
    "    cat(\"Model \",model,\":\")\n",
    "    cat(\"\\n===============================================\\n\")\n",
    "\n",
    "    cat(\"\\n\\nCoefficients from Linear model (adjust_for effects omitted):\\n\")\n",
    "\n",
    "    # catch the re-ordering of interaction terms introduced by the update(form,dev.new ~ .) call in cluster.wild.glm\n",
    "    tryCatch({\n",
    "        print(coef(summary(LM))[predictors,])    \n",
    "    },error = function(err){\n",
    "        model_coef = dimnames(coef(summary(LM)))[[1]]\n",
    "        cat(\"\\n=------------------------======================\\n\")\n",
    "            print(FMLA)\n",
    "            print(coef(summary(LM)))\n",
    "        cat(\"\\n=------------------------======================\\n\")\n",
    "        cat(\"Missing coefficients:\\n\",\n",
    "            predictors[! predictors %in% model_coef])\n",
    "        cat(\"\\n\\nAvailable coefficients:\\n\")\n",
    "\n",
    "        print(model_coef)\n",
    "        stop(err)\n",
    "    })\n",
    "        cat(sprintf(\"Finished the summary in %s seconds\\n\",round(Sys.time() - start,3)))\n",
    "\n",
    "    # DO THE WILD BOOTSTRAP\n",
    "    # set.seed(10101)\n",
    "    # cl <-cluster.wild.glm(LM, dat = data, cluster = ~ factor(favorite_route), boot.reps = boot.reps, report=FALSE )\n",
    "    gc()\n",
    "    cat(sprintf(\"Starting the wild bootstraps...at %s\\n\",round(Sys.time() - begin,3)))\n",
    "    cl <-cluster.wild.glm(LM,\n",
    "                          dat = data,\n",
    "                          cluster = cluster_on,\n",
    "                          boot.reps = ifelse(quick,3,boot.reps),\n",
    "                          report=FALSE,\n",
    "                          dopar=TRUE,\n",
    "                          seed=seed)\n",
    "\n",
    "    cat(\"Finished the wild bootstraps...\\n\")\n",
    "        cat(sprintf(\"Finished wild bootstraps in %s seconds\\n\",round(Sys.time() - start,3)))\n",
    "    # MAKE THE PRETTY OUTPUT\n",
    "    CI = rbind(cl$ci[predictors,])\n",
    "\n",
    "    out <- cbind(model=model,\n",
    "                        \"OLS Estimate\"=coef(summary(LM))[predictors,\"Estimate\"],\n",
    "                        \"BS p-value\"=cl$p.values[predictors,],\n",
    "                        CI,\n",
    "                        N=data[,.N],\n",
    "                        granularity=granularity)\n",
    "    dimnames(out)[[1]] <- predictors\n",
    "\n",
    "    rm(LM,cl); gc() # alas...\n",
    "    # dimnames(out)[[1]] <- predictors\n",
    "    return(out)\n",
    "\n",
    "} "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Fit the Models for table 2\n",
    "* Pre 520 HOV data only"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "in progress\n",
      "Starting at 2020-07-03 17:55:38Starting the base glm (OLS) model...at 0.101\n",
      "Finished the base glm (OLS) model... in 9.206 seconds\n",
      "Starting the summary()...at 9.308\n",
      "\n",
      "===============================================\n",
      "Model  1 :\n",
      "===============================================\n",
      "\n",
      "\n",
      "Coefficients from Linear model (adjust_for effects omitted):\n",
      "    Estimate   Std. Error      t value     Pr(>|t|) \n",
      "2.356434e-02 1.421748e-03 1.657420e+01 1.089323e-61 \n",
      "Finished the summary in 0.951 seconds\n",
      "Starting the wild bootstraps...at 10.733\n",
      "\n",
      " \n",
      " Note: null not imposed (factor variables are present). \n",
      " \n",
      "else... \n",
      "Wild Cluster bootstrapping w/o imposing null... \n",
      "================================================================================\n",
      "Id: job20200704005629\n",
      "chunkSize: 1\n",
      "enableCloudCombine: TRUE\n",
      "errorHandling: stop\n",
      "wait: TRUE\n",
      "autoDeleteJob: TRUE\n",
      "================================================================================\n",
      "Submitting tasks (1001/1001)\n",
      "Submitting merge task. . .\n",
      "Waiting for tasks to complete. . .\n",
      "| Progress: 100.00% (1001/1001) | Running: 0 | Queued: 0 | Completed: 1001 | Failed: 0 |\n",
      "Tasks have completed. Merging results..... Completed.\n",
      "Finished the wild bootstraps...\n",
      "Finished wild bootstraps in 9.219 seconds\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<thead><tr><th></th><th scope=col>model</th><th scope=col>OLS Estimate</th><th scope=col>BS p-value</th><th scope=col>CI lower</th><th scope=col>CI higher</th><th scope=col>N</th><th scope=col>granularity</th></tr></thead>\n",
       "<tbody>\n",
       "\t<tr><th scope=row>imputed_new_buses</th><td>1                           </td><td>0.0235643378914852          </td><td>0                           </td><td>0.0109217227329597          </td><td>0.0362069530500107          </td><td>1104348                     </td><td>rider/date/commute [Pre-HOV]</td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "\\begin{tabular}{r|lllllll}\n",
       "  & model & OLS Estimate & BS p-value & CI lower & CI higher & N & granularity\\\\\n",
       "\\hline\n",
       "\timputed\\_new\\_buses & 1                                & 0.0235643378914852               & 0                                & 0.0109217227329597               & 0.0362069530500107               & 1104348                          & rider/date/commute {[}Pre-HOV{]}\\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "| <!--/--> | model | OLS Estimate | BS p-value | CI lower | CI higher | N | granularity |\n",
       "|---|---|---|---|---|---|---|---|\n",
       "| imputed_new_buses | 1                            | 0.0235643378914852           | 0                            | 0.0109217227329597           | 0.0362069530500107           | 1104348                      | rider/date/commute [Pre-HOV] |\n",
       "\n"
      ],
      "text/plain": [
       "                  model OLS Estimate       BS p-value CI lower          \n",
       "imputed_new_buses 1     0.0235643378914852 0          0.0109217227329597\n",
       "                  CI higher          N       granularity                 \n",
       "imputed_new_buses 0.0362069530500107 1104348 rider/date/commute [Pre-HOV]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "cat(\"in progress\\n\")\n",
    "(table2_model1_pre_HOV = fit_ridership_logit_models(data = commute_ride_data[(!SR520WBHOV) &  (!SR520EBHOV)],\n",
    "                            predictors=c(\"imputed_new_buses\"),\n",
    "                            adjust_for=c( \"f_favorite_route\", \"f_commutes_since_last_ride\"),\n",
    "                            model=1,\n",
    "                            granularity=\"rider/date/commute [Pre-HOV]\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "in progress\n",
      "Starting at 2020-07-03 18:05:01Starting the base glm (OLS) model...at 0.098\n",
      "Finished the base glm (OLS) model... in 9.232 seconds\n",
      "Starting the summary()...at 9.331\n",
      "\n",
      "===============================================\n",
      "Model  2 :\n",
      "===============================================\n",
      "\n",
      "\n",
      "Coefficients from Linear model (adjust_for effects omitted):\n",
      "                                            Estimate  Std. Error  t value\n",
      "imputed_new_buses                        0.020245784 0.002117828 9.559692\n",
      "imputed_new_buses:IsRouteSeattle_10_ride 0.005981643 0.002829290 2.114185\n",
      "                                             Pr(>|t|)\n",
      "imputed_new_buses                        1.183355e-21\n",
      "imputed_new_buses:IsRouteSeattle_10_ride 3.449967e-02\n",
      "Finished the summary in 0.646 seconds\n",
      "Starting the wild bootstraps...at 10.609\n",
      "\n",
      " \n",
      " Note: null not imposed (factor variables are present). \n",
      " \n",
      "else... \n",
      "Wild Cluster bootstrapping w/o imposing null... \n",
      "================================================================================\n",
      "Id: job20200704010553\n",
      "chunkSize: 1\n",
      "enableCloudCombine: TRUE\n",
      "errorHandling: stop\n",
      "wait: TRUE\n",
      "autoDeleteJob: TRUE\n",
      "================================================================================\n",
      "Submitting tasks (1001/1001)\n",
      "Submitting merge task. . .\n",
      "Waiting for tasks to complete. . .\n",
      "| Progress: 100.00% (1001/1001) | Running: 0 | Queued: 0 | Completed: 1001 | Failed: 0 |\n",
      "Tasks have completed. Merging results...... Completed.\n",
      "Finished the wild bootstraps...\n",
      "Finished wild bootstraps in 9.378 seconds\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<thead><tr><th></th><th scope=col>model</th><th scope=col>OLS Estimate</th><th scope=col>BS p-value</th><th scope=col>CI lower</th><th scope=col>CI higher</th><th scope=col>N</th><th scope=col>granularity</th></tr></thead>\n",
       "<tbody>\n",
       "\t<tr><th scope=row>imputed_new_buses</th><td>2                           </td><td>0.0202457843501052          </td><td>0.108891108891109           </td><td>-0.00303352246619289        </td><td>0.0435250911664033          </td><td>1104348                     </td><td>rider/date/commute [Pre-HOV]</td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:IsRouteSeattle_10_ride</th><td>2                           </td><td>0.00598164268673898         </td><td>0.74025974025974            </td><td>-0.0195826163881079         </td><td>0.0315459017615859          </td><td>1104348                     </td><td>rider/date/commute [Pre-HOV]</td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "\\begin{tabular}{r|lllllll}\n",
       "  & model & OLS Estimate & BS p-value & CI lower & CI higher & N & granularity\\\\\n",
       "\\hline\n",
       "\timputed\\_new\\_buses & 2                                & 0.0202457843501052               & 0.108891108891109                & -0.00303352246619289             & 0.0435250911664033               & 1104348                          & rider/date/commute {[}Pre-HOV{]}\\\\\n",
       "\timputed\\_new\\_buses:IsRouteSeattle\\_10\\_ride & 2                                & 0.00598164268673898              & 0.74025974025974                 & -0.0195826163881079              & 0.0315459017615859               & 1104348                          & rider/date/commute {[}Pre-HOV{]}\\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "| <!--/--> | model | OLS Estimate | BS p-value | CI lower | CI higher | N | granularity |\n",
       "|---|---|---|---|---|---|---|---|\n",
       "| imputed_new_buses | 2                            | 0.0202457843501052           | 0.108891108891109            | -0.00303352246619289         | 0.0435250911664033           | 1104348                      | rider/date/commute [Pre-HOV] |\n",
       "| imputed_new_buses:IsRouteSeattle_10_ride | 2                            | 0.00598164268673898          | 0.74025974025974             | -0.0195826163881079          | 0.0315459017615859           | 1104348                      | rider/date/commute [Pre-HOV] |\n",
       "\n"
      ],
      "text/plain": [
       "                                         model OLS Estimate       \n",
       "imputed_new_buses                        2     0.0202457843501052 \n",
       "imputed_new_buses:IsRouteSeattle_10_ride 2     0.00598164268673898\n",
       "                                         BS p-value        CI lower            \n",
       "imputed_new_buses                        0.108891108891109 -0.00303352246619289\n",
       "imputed_new_buses:IsRouteSeattle_10_ride 0.74025974025974  -0.0195826163881079 \n",
       "                                         CI higher          N      \n",
       "imputed_new_buses                        0.0435250911664033 1104348\n",
       "imputed_new_buses:IsRouteSeattle_10_ride 0.0315459017615859 1104348\n",
       "                                         granularity                 \n",
       "imputed_new_buses                        rider/date/commute [Pre-HOV]\n",
       "imputed_new_buses:IsRouteSeattle_10_ride rider/date/commute [Pre-HOV]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "cat(\"in progress\\n\")\n",
    "(table2_model2 = fit_ridership_logit_models(data = commute_ride_data[(!SR520WBHOV) & \n",
    "                                                            (!SR520EBHOV)],\n",
    "                            predictors=c(\"imputed_new_buses\",\n",
    "                                            \"imputed_new_buses:IsRouteSeattle_10_ride\"),\n",
    "                            adjust_for=c( \"f_favorite_route\", \"f_commutes_since_last_ride\"),\n",
    "                            model=2,\n",
    "                            granularity=\"rider/date/commute [Pre-HOV]\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "in progress\n",
      "Starting at 2020-07-03 18:14:34Starting the base glm (OLS) model...at 0.067\n",
      "Finished the base glm (OLS) model... in 3.347 seconds\n",
      "Starting the summary()...at 3.414\n",
      "\n",
      "===============================================\n",
      "Model  3 :\n",
      "===============================================\n",
      "\n",
      "\n",
      "Coefficients from Linear model (adjust_for effects omitted):\n",
      "                                             Estimate  Std. Error    t value\n",
      "imputed_new_buses                         0.028774350 0.002807522 10.2490207\n",
      "imputed_new_buses:IsRouteSeattle_10_ride -0.002710307 0.003998932 -0.6777578\n",
      "                                             Pr(>|t|)\n",
      "imputed_new_buses                        1.202632e-24\n",
      "imputed_new_buses:IsRouteSeattle_10_ride 4.979256e-01\n",
      "Finished the summary in 0.284 seconds\n",
      "Starting the wild bootstraps...at 4.204\n",
      "\n",
      " \n",
      " Note: null not imposed (factor variables are present). \n",
      " \n",
      "else... \n",
      "Wild Cluster bootstrapping w/o imposing null... \n",
      "================================================================================\n",
      "Id: job20200704011455\n",
      "chunkSize: 1\n",
      "enableCloudCombine: TRUE\n",
      "errorHandling: stop\n",
      "wait: TRUE\n",
      "autoDeleteJob: TRUE\n",
      "================================================================================\n",
      "Submitting tasks (1001/1001)\n",
      "Submitting merge task. . .\n",
      "Waiting for tasks to complete. . .\n",
      "| Progress: 100.00% (1001/1001) | Running: 0 | Queued: 0 | Completed: 1001 | Failed: 0 |\n",
      "Tasks have completed. Merging results... Completed.\n",
      "Finished the wild bootstraps...\n",
      "Finished wild bootstraps in 4.286 seconds\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<thead><tr><th></th><th scope=col>model</th><th scope=col>OLS Estimate</th><th scope=col>BS p-value</th><th scope=col>CI lower</th><th scope=col>CI higher</th><th scope=col>N</th><th scope=col>granularity</th></tr></thead>\n",
       "<tbody>\n",
       "\t<tr><th scope=row>imputed_new_buses</th><td>3                                                        </td><td>0.0287743502789941                                       </td><td>0.150849150849151                                        </td><td>-0.00584619735525286                                     </td><td>0.0633948979132411                                       </td><td>471656                                                   </td><td>rider/date/commute [Pre-HOV; First stop preferred riders]</td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:IsRouteSeattle_10_ride</th><td>3                                                        </td><td>-0.00271030714203348                                     </td><td>0.898101898101898                                        </td><td>-0.0393126279437267                                      </td><td>0.0338920136596597                                       </td><td>471656                                                   </td><td>rider/date/commute [Pre-HOV; First stop preferred riders]</td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "\\begin{tabular}{r|lllllll}\n",
       "  & model & OLS Estimate & BS p-value & CI lower & CI higher & N & granularity\\\\\n",
       "\\hline\n",
       "\timputed\\_new\\_buses & 3                                                             & 0.0287743502789941                                            & 0.150849150849151                                             & -0.00584619735525286                                          & 0.0633948979132411                                            & 471656                                                        & rider/date/commute {[}Pre-HOV; First stop preferred riders{]}\\\\\n",
       "\timputed\\_new\\_buses:IsRouteSeattle\\_10\\_ride & 3                                                             & -0.00271030714203348                                          & 0.898101898101898                                             & -0.0393126279437267                                           & 0.0338920136596597                                            & 471656                                                        & rider/date/commute {[}Pre-HOV; First stop preferred riders{]}\\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "| <!--/--> | model | OLS Estimate | BS p-value | CI lower | CI higher | N | granularity |\n",
       "|---|---|---|---|---|---|---|---|\n",
       "| imputed_new_buses | 3                                                         | 0.0287743502789941                                        | 0.150849150849151                                         | -0.00584619735525286                                      | 0.0633948979132411                                        | 471656                                                    | rider/date/commute [Pre-HOV; First stop preferred riders] |\n",
       "| imputed_new_buses:IsRouteSeattle_10_ride | 3                                                         | -0.00271030714203348                                      | 0.898101898101898                                         | -0.0393126279437267                                       | 0.0338920136596597                                        | 471656                                                    | rider/date/commute [Pre-HOV; First stop preferred riders] |\n",
       "\n"
      ],
      "text/plain": [
       "                                         model OLS Estimate        \n",
       "imputed_new_buses                        3     0.0287743502789941  \n",
       "imputed_new_buses:IsRouteSeattle_10_ride 3     -0.00271030714203348\n",
       "                                         BS p-value        CI lower            \n",
       "imputed_new_buses                        0.150849150849151 -0.00584619735525286\n",
       "imputed_new_buses:IsRouteSeattle_10_ride 0.898101898101898 -0.0393126279437267 \n",
       "                                         CI higher          N     \n",
       "imputed_new_buses                        0.0633948979132411 471656\n",
       "imputed_new_buses:IsRouteSeattle_10_ride 0.0338920136596597 471656\n",
       "                                         granularity                                              \n",
       "imputed_new_buses                        rider/date/commute [Pre-HOV; First stop preferred riders]\n",
       "imputed_new_buses:IsRouteSeattle_10_ride rider/date/commute [Pre-HOV; First stop preferred riders]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "cat(\"in progress\\n\")\n",
    "(table2_model3_pre_HOV = fit_ridership_logit_models(data = commute_ride_data[(!SR520WBHOV) &  \n",
    "                                                            (!SR520EBHOV) & \n",
    "                                                            (first_stop_10_ride >= 0.5)],\n",
    "                            predictors=c(\"imputed_new_buses\",\n",
    "                                            \"imputed_new_buses:IsRouteSeattle_10_ride\"),\n",
    "                            adjust_for=c( \"f_favorite_route\", \"f_commutes_since_last_ride\"),\n",
    "                            model=3,\n",
    "                            granularity=\"rider/date/commute [Pre-HOV; First stop preferred riders]\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "in progress\n",
      "Starting at 2020-07-03 18:18:55Starting the base glm (OLS) model...at 0.089\n",
      "Finished the base glm (OLS) model... in 6.293 seconds\n",
      "Starting the summary()...at 6.383\n",
      "\n",
      "===============================================\n",
      "Model  4 :\n",
      "===============================================\n",
      "\n",
      "\n",
      "Coefficients from Linear model (adjust_for effects omitted):\n",
      "                                           Estimate  Std. Error  t value\n",
      "imputed_new_buses                        0.02108386 0.002379597 8.860264\n",
      "imputed_new_buses:IsRouteSeattle_10_ride 0.00766025 0.003345436 2.289762\n",
      "                                             Pr(>|t|)\n",
      "imputed_new_buses                        7.999268e-19\n",
      "imputed_new_buses:IsRouteSeattle_10_ride 2.203541e-02\n",
      "Finished the summary in 0.445 seconds\n",
      "Starting the wild bootstraps...at 7.199\n",
      "\n",
      " \n",
      " Note: null not imposed (factor variables are present). \n",
      " \n",
      "else... \n",
      "Wild Cluster bootstrapping w/o imposing null... \n",
      "================================================================================\n",
      "Id: job20200704011931\n",
      "chunkSize: 1\n",
      "enableCloudCombine: TRUE\n",
      "errorHandling: stop\n",
      "wait: TRUE\n",
      "autoDeleteJob: TRUE\n",
      "================================================================================\n",
      "Submitting tasks (1001/1001)\n",
      "Submitting merge task. . .\n",
      "Waiting for tasks to complete. . .\n",
      "| Progress: 100.00% (1001/1001) | Running: 0 | Queued: 0 | Completed: 1001 | Failed: 0 |\n",
      "Tasks have completed. Merging results... Completed.\n",
      "Finished the wild bootstraps...\n",
      "Finished wild bootstraps in 6.302 seconds\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<thead><tr><th></th><th scope=col>model</th><th scope=col>OLS Estimate</th><th scope=col>BS p-value</th><th scope=col>CI lower</th><th scope=col>CI higher</th><th scope=col>N</th><th scope=col>granularity</th></tr></thead>\n",
       "<tbody>\n",
       "\t<tr><th scope=row>imputed_new_buses</th><td>4                                                       </td><td>0.0210838592663638                                      </td><td>0.150849150849151                                       </td><td>-0.00651366616844423                                    </td><td>0.0486813847011718                                      </td><td>753890                                                  </td><td>rider/date/commute [Pre-HOV; Last stop preferred riders]</td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:IsRouteSeattle_10_ride</th><td>4                                                       </td><td>0.00766025028206265                                     </td><td>0.684315684315684                                       </td><td>-0.020999466676143                                      </td><td>0.0363199672402683                                      </td><td>753890                                                  </td><td>rider/date/commute [Pre-HOV; Last stop preferred riders]</td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "\\begin{tabular}{r|lllllll}\n",
       "  & model & OLS Estimate & BS p-value & CI lower & CI higher & N & granularity\\\\\n",
       "\\hline\n",
       "\timputed\\_new\\_buses & 4                                                            & 0.0210838592663638                                           & 0.150849150849151                                            & -0.00651366616844423                                         & 0.0486813847011718                                           & 753890                                                       & rider/date/commute {[}Pre-HOV; Last stop preferred riders{]}\\\\\n",
       "\timputed\\_new\\_buses:IsRouteSeattle\\_10\\_ride & 4                                                            & 0.00766025028206265                                          & 0.684315684315684                                            & -0.020999466676143                                           & 0.0363199672402683                                           & 753890                                                       & rider/date/commute {[}Pre-HOV; Last stop preferred riders{]}\\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "| <!--/--> | model | OLS Estimate | BS p-value | CI lower | CI higher | N | granularity |\n",
       "|---|---|---|---|---|---|---|---|\n",
       "| imputed_new_buses | 4                                                        | 0.0210838592663638                                       | 0.150849150849151                                        | -0.00651366616844423                                     | 0.0486813847011718                                       | 753890                                                   | rider/date/commute [Pre-HOV; Last stop preferred riders] |\n",
       "| imputed_new_buses:IsRouteSeattle_10_ride | 4                                                        | 0.00766025028206265                                      | 0.684315684315684                                        | -0.020999466676143                                       | 0.0363199672402683                                       | 753890                                                   | rider/date/commute [Pre-HOV; Last stop preferred riders] |\n",
       "\n"
      ],
      "text/plain": [
       "                                         model OLS Estimate       \n",
       "imputed_new_buses                        4     0.0210838592663638 \n",
       "imputed_new_buses:IsRouteSeattle_10_ride 4     0.00766025028206265\n",
       "                                         BS p-value        CI lower            \n",
       "imputed_new_buses                        0.150849150849151 -0.00651366616844423\n",
       "imputed_new_buses:IsRouteSeattle_10_ride 0.684315684315684 -0.020999466676143  \n",
       "                                         CI higher          N     \n",
       "imputed_new_buses                        0.0486813847011718 753890\n",
       "imputed_new_buses:IsRouteSeattle_10_ride 0.0363199672402683 753890\n",
       "                                         granularity                                             \n",
       "imputed_new_buses                        rider/date/commute [Pre-HOV; Last stop preferred riders]\n",
       "imputed_new_buses:IsRouteSeattle_10_ride rider/date/commute [Pre-HOV; Last stop preferred riders]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "cat(\"in progress\\n\")\n",
    "(table2_model4_pre_HOV = fit_ridership_logit_models(data = commute_ride_data[(!SR520WBHOV) & \n",
    "                                                            (!SR520EBHOV) & \n",
    "                                                            (last_stop_10_ride >= 0.5)],\n",
    "                            predictors=c(\"imputed_new_buses\",\n",
    "                                            \"imputed_new_buses:IsRouteSeattle_10_ride\"),\n",
    "                            adjust_for=c( \"f_favorite_route\", \"f_commutes_since_last_ride\"),\n",
    "                            model=4,\n",
    "                            granularity=\"rider/date/commute [Pre-HOV; Last stop preferred riders]\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "in progress\n",
      "Starting at 2020-07-03 18:25:21Starting the base glm (OLS) model...at 0.09\n",
      "Finished the base glm (OLS) model... in 5.682 seconds\n",
      "Starting the summary()...at 5.772\n",
      "\n",
      "===============================================\n",
      "Model  5 :\n",
      "===============================================\n",
      "\n",
      "\n",
      "Coefficients from Linear model (adjust_for effects omitted):\n",
      "    Estimate   Std. Error      t value     Pr(>|t|) \n",
      "2.564115e-02 1.931076e-03 1.327817e+01 3.132156e-40 \n",
      "Finished the summary in 0.416 seconds\n",
      "Starting the wild bootstraps...at 6.774\n",
      "\n",
      " \n",
      " Note: null not imposed (factor variables are present). \n",
      " \n",
      "else... \n",
      "Wild Cluster bootstrapping w/o imposing null... \n",
      "================================================================================\n",
      "Id: job20200704012552\n",
      "chunkSize: 1\n",
      "enableCloudCombine: TRUE\n",
      "errorHandling: stop\n",
      "wait: TRUE\n",
      "autoDeleteJob: TRUE\n",
      "================================================================================\n",
      "Submitting tasks (1001/1001)\n",
      "Submitting merge task. . .\n",
      "Waiting for tasks to complete. . .\n",
      "| Progress: 100.00% (1001/1001) | Running: 0 | Queued: 0 | Completed: 1001 | Failed: 0 |\n",
      "Tasks have completed. Merging results.... Completed.\n",
      "Finished the wild bootstraps...\n",
      "Finished wild bootstraps in 5.824 seconds\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<thead><tr><th></th><th scope=col>model</th><th scope=col>OLS Estimate</th><th scope=col>BS p-value</th><th scope=col>CI lower</th><th scope=col>CI higher</th><th scope=col>N</th><th scope=col>granularity</th></tr></thead>\n",
       "<tbody>\n",
       "\t<tr><th scope=row>imputed_new_buses</th><td>5                                                     </td><td>0.0256411475012276                                    </td><td>0                                                     </td><td>0.0128627832501194                                    </td><td>0.0384195117523358                                    </td><td>733928                                                </td><td>rider/date/commute [Pre-HOV; Seattle preferred riders]</td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "\\begin{tabular}{r|lllllll}\n",
       "  & model & OLS Estimate & BS p-value & CI lower & CI higher & N & granularity\\\\\n",
       "\\hline\n",
       "\timputed\\_new\\_buses & 5                                                          & 0.0256411475012276                                         & 0                                                          & 0.0128627832501194                                         & 0.0384195117523358                                         & 733928                                                     & rider/date/commute {[}Pre-HOV; Seattle preferred riders{]}\\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "| <!--/--> | model | OLS Estimate | BS p-value | CI lower | CI higher | N | granularity |\n",
       "|---|---|---|---|---|---|---|---|\n",
       "| imputed_new_buses | 5                                                      | 0.0256411475012276                                     | 0                                                      | 0.0128627832501194                                     | 0.0384195117523358                                     | 733928                                                 | rider/date/commute [Pre-HOV; Seattle preferred riders] |\n",
       "\n"
      ],
      "text/plain": [
       "                  model OLS Estimate       BS p-value CI lower          \n",
       "imputed_new_buses 5     0.0256411475012276 0          0.0128627832501194\n",
       "                  CI higher          N     \n",
       "imputed_new_buses 0.0384195117523358 733928\n",
       "                  granularity                                           \n",
       "imputed_new_buses rider/date/commute [Pre-HOV; Seattle preferred riders]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "cat(\"in progress\\n\")\n",
    "(table2_model5_pre_HOV = fit_ridership_logit_models(data = commute_ride_data[(!SR520WBHOV) & \n",
    "                                                            (!SR520EBHOV) & \n",
    "                                                            IsRouteSeattle_10_ride >= 0.5],\n",
    "                            predictors=c(\"imputed_new_buses\"),\n",
    "                            adjust_for=c( \"f_favorite_route\", \"f_commutes_since_last_ride\"),\n",
    "                            model=5,\n",
    "                            granularity=\"rider/date/commute [Pre-HOV; Seattle preferred riders]\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "in progress\n",
      "Starting at 2020-07-03 18:31:16Starting the base glm (OLS) model...at 0.05\n",
      "Finished the base glm (OLS) model... in 2.26 seconds\n",
      "Starting the summary()...at 2.31\n",
      "\n",
      "===============================================\n",
      "Model  6 :\n",
      "===============================================\n",
      "\n",
      "\n",
      "Coefficients from Linear model (adjust_for effects omitted):\n",
      "    Estimate   Std. Error      t value     Pr(>|t|) \n",
      "2.108755e-02 2.075689e-03 1.015930e+01 3.034485e-24 \n",
      "Finished the summary in 0.21 seconds\n",
      "Starting the wild bootstraps...at 2.917\n",
      "\n",
      " \n",
      " Note: null not imposed (factor variables are present). \n",
      " \n",
      "else... \n",
      "Wild Cluster bootstrapping w/o imposing null... \n",
      "================================================================================\n",
      "Id: job20200704013131\n",
      "chunkSize: 1\n",
      "enableCloudCombine: TRUE\n",
      "errorHandling: stop\n",
      "wait: TRUE\n",
      "autoDeleteJob: TRUE\n",
      "================================================================================\n",
      "Submitting tasks (1001/1001)\n",
      "Submitting merge task. . .\n",
      "Waiting for tasks to complete. . .\n",
      "| Progress: 100.00% (1001/1001) | Running: 0 | Queued: 0 | Completed: 1001 | Failed: 0 |\n",
      "Tasks have completed. Merging results.... Completed.\n",
      "Finished the wild bootstraps...\n",
      "Finished wild bootstraps in 3.448 seconds\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<thead><tr><th></th><th scope=col>model</th><th scope=col>OLS Estimate</th><th scope=col>BS p-value</th><th scope=col>CI lower</th><th scope=col>CI higher</th><th scope=col>N</th><th scope=col>granularity</th></tr></thead>\n",
       "<tbody>\n",
       "\t<tr><th scope=row>imputed_new_buses</th><td>6                                                         </td><td>0.0210875463340533                                        </td><td>0.035964035964036                                         </td><td>0.000309723607852603                                      </td><td>0.0418653690602541                                        </td><td>370670                                                    </td><td>rider/date/commute [Pre-HOV; Non-Seattle preferred riders]</td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "\\begin{tabular}{r|lllllll}\n",
       "  & model & OLS Estimate & BS p-value & CI lower & CI higher & N & granularity\\\\\n",
       "\\hline\n",
       "\timputed\\_new\\_buses & 6                                                              & 0.0210875463340533                                             & 0.035964035964036                                              & 0.000309723607852603                                           & 0.0418653690602541                                             & 370670                                                         & rider/date/commute {[}Pre-HOV; Non-Seattle preferred riders{]}\\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "| <!--/--> | model | OLS Estimate | BS p-value | CI lower | CI higher | N | granularity |\n",
       "|---|---|---|---|---|---|---|---|\n",
       "| imputed_new_buses | 6                                                          | 0.0210875463340533                                         | 0.035964035964036                                          | 0.000309723607852603                                       | 0.0418653690602541                                         | 370670                                                     | rider/date/commute [Pre-HOV; Non-Seattle preferred riders] |\n",
       "\n"
      ],
      "text/plain": [
       "                  model OLS Estimate       BS p-value       \n",
       "imputed_new_buses 6     0.0210875463340533 0.035964035964036\n",
       "                  CI lower             CI higher          N     \n",
       "imputed_new_buses 0.000309723607852603 0.0418653690602541 370670\n",
       "                  granularity                                               \n",
       "imputed_new_buses rider/date/commute [Pre-HOV; Non-Seattle preferred riders]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "cat(\"in progress\\n\")\n",
    "(table2_model6_pre_HOV = fit_ridership_logit_models(data = commute_ride_data[(!SR520WBHOV) & \n",
    "                                                            (!SR520EBHOV) & \n",
    "                                                            IsRouteSeattle_10_ride <= 0.5],\n",
    "                            predictors=c(\"imputed_new_buses\"),\n",
    "                            adjust_for=c(\"f_favorite_route\",  \"f_commutes_since_last_ride\"),\n",
    "                            model=6,\n",
    "                            granularity=\"rider/date/commute [Pre-HOV; Non-Seattle preferred riders]\"))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Table 2 Summary Statistics \n",
    "* Pre 520 HOV data only"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<thead><tr><th></th><th scope=col>model</th><th scope=col>OLS Estimate</th><th scope=col>BS p-value</th><th scope=col>CI lower</th><th scope=col>CI higher</th><th scope=col>N</th><th scope=col>granularity</th></tr></thead>\n",
       "<tbody>\n",
       "\t<tr><th scope=row>imputed_new_buses</th><td>1                                                         </td><td>0.0235643378914852                                        </td><td>0                                                         </td><td>0.0109217227329597                                        </td><td>0.0362069530500107                                        </td><td>1104348                                                   </td><td>rider/date/commute [Pre-HOV]                              </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses</th><td>2                                                         </td><td>0.0202457843501052                                        </td><td>0.108891108891109                                         </td><td>-0.00303352246619289                                      </td><td>0.0435250911664033                                        </td><td>1104348                                                   </td><td>rider/date/commute [Pre-HOV]                              </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:IsRouteSeattle_10_ride</th><td>2                                                         </td><td>0.00598164268673898                                       </td><td>0.74025974025974                                          </td><td>-0.0195826163881079                                       </td><td>0.0315459017615859                                        </td><td>1104348                                                   </td><td>rider/date/commute [Pre-HOV]                              </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses</th><td>3                                                         </td><td>0.0287743502789941                                        </td><td>0.150849150849151                                         </td><td>-0.00584619735525286                                      </td><td>0.0633948979132411                                        </td><td>471656                                                    </td><td>rider/date/commute [Pre-HOV; First stop preferred riders] </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:IsRouteSeattle_10_ride</th><td>3                                                         </td><td>-0.00271030714203348                                      </td><td>0.898101898101898                                         </td><td>-0.0393126279437267                                       </td><td>0.0338920136596597                                        </td><td>471656                                                    </td><td>rider/date/commute [Pre-HOV; First stop preferred riders] </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses</th><td>4                                                         </td><td>0.0210838592663638                                        </td><td>0.150849150849151                                         </td><td>-0.00651366616844423                                      </td><td>0.0486813847011718                                        </td><td>753890                                                    </td><td>rider/date/commute [Pre-HOV; Last stop preferred riders]  </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:IsRouteSeattle_10_ride</th><td>4                                                         </td><td>0.00766025028206265                                       </td><td>0.684315684315684                                         </td><td>-0.020999466676143                                        </td><td>0.0363199672402683                                        </td><td>753890                                                    </td><td>rider/date/commute [Pre-HOV; Last stop preferred riders]  </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses</th><td>5                                                         </td><td>0.0256411475012276                                        </td><td>0                                                         </td><td>0.0128627832501194                                        </td><td>0.0384195117523358                                        </td><td>733928                                                    </td><td>rider/date/commute [Pre-HOV; Seattle preferred riders]    </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses</th><td>6                                                         </td><td>0.0210875463340533                                        </td><td>0.035964035964036                                         </td><td>0.000309723607852603                                      </td><td>0.0418653690602541                                        </td><td>370670                                                    </td><td>rider/date/commute [Pre-HOV; Non-Seattle preferred riders]</td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "\\begin{tabular}{r|lllllll}\n",
       "  & model & OLS Estimate & BS p-value & CI lower & CI higher & N & granularity\\\\\n",
       "\\hline\n",
       "\timputed\\_new\\_buses & 1                                                              & 0.0235643378914852                                             & 0                                                              & 0.0109217227329597                                             & 0.0362069530500107                                             & 1104348                                                        & rider/date/commute {[}Pre-HOV{]}                              \\\\\n",
       "\timputed\\_new\\_buses & 2                                                              & 0.0202457843501052                                             & 0.108891108891109                                              & -0.00303352246619289                                           & 0.0435250911664033                                             & 1104348                                                        & rider/date/commute {[}Pre-HOV{]}                              \\\\\n",
       "\timputed\\_new\\_buses:IsRouteSeattle\\_10\\_ride & 2                                                              & 0.00598164268673898                                            & 0.74025974025974                                               & -0.0195826163881079                                            & 0.0315459017615859                                             & 1104348                                                        & rider/date/commute {[}Pre-HOV{]}                              \\\\\n",
       "\timputed\\_new\\_buses & 3                                                              & 0.0287743502789941                                             & 0.150849150849151                                              & -0.00584619735525286                                           & 0.0633948979132411                                             & 471656                                                         & rider/date/commute {[}Pre-HOV; First stop preferred riders{]} \\\\\n",
       "\timputed\\_new\\_buses:IsRouteSeattle\\_10\\_ride & 3                                                              & -0.00271030714203348                                           & 0.898101898101898                                              & -0.0393126279437267                                            & 0.0338920136596597                                             & 471656                                                         & rider/date/commute {[}Pre-HOV; First stop preferred riders{]} \\\\\n",
       "\timputed\\_new\\_buses & 4                                                              & 0.0210838592663638                                             & 0.150849150849151                                              & -0.00651366616844423                                           & 0.0486813847011718                                             & 753890                                                         & rider/date/commute {[}Pre-HOV; Last stop preferred riders{]}  \\\\\n",
       "\timputed\\_new\\_buses:IsRouteSeattle\\_10\\_ride & 4                                                              & 0.00766025028206265                                            & 0.684315684315684                                              & -0.020999466676143                                             & 0.0363199672402683                                             & 753890                                                         & rider/date/commute {[}Pre-HOV; Last stop preferred riders{]}  \\\\\n",
       "\timputed\\_new\\_buses & 5                                                              & 0.0256411475012276                                             & 0                                                              & 0.0128627832501194                                             & 0.0384195117523358                                             & 733928                                                         & rider/date/commute {[}Pre-HOV; Seattle preferred riders{]}    \\\\\n",
       "\timputed\\_new\\_buses & 6                                                              & 0.0210875463340533                                             & 0.035964035964036                                              & 0.000309723607852603                                           & 0.0418653690602541                                             & 370670                                                         & rider/date/commute {[}Pre-HOV; Non-Seattle preferred riders{]}\\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "| <!--/--> | model | OLS Estimate | BS p-value | CI lower | CI higher | N | granularity |\n",
       "|---|---|---|---|---|---|---|---|\n",
       "| imputed_new_buses | 1                                                          | 0.0235643378914852                                         | 0                                                          | 0.0109217227329597                                         | 0.0362069530500107                                         | 1104348                                                    | rider/date/commute [Pre-HOV]                               |\n",
       "| imputed_new_buses | 2                                                          | 0.0202457843501052                                         | 0.108891108891109                                          | -0.00303352246619289                                       | 0.0435250911664033                                         | 1104348                                                    | rider/date/commute [Pre-HOV]                               |\n",
       "| imputed_new_buses:IsRouteSeattle_10_ride | 2                                                          | 0.00598164268673898                                        | 0.74025974025974                                           | -0.0195826163881079                                        | 0.0315459017615859                                         | 1104348                                                    | rider/date/commute [Pre-HOV]                               |\n",
       "| imputed_new_buses | 3                                                          | 0.0287743502789941                                         | 0.150849150849151                                          | -0.00584619735525286                                       | 0.0633948979132411                                         | 471656                                                     | rider/date/commute [Pre-HOV; First stop preferred riders]  |\n",
       "| imputed_new_buses:IsRouteSeattle_10_ride | 3                                                          | -0.00271030714203348                                       | 0.898101898101898                                          | -0.0393126279437267                                        | 0.0338920136596597                                         | 471656                                                     | rider/date/commute [Pre-HOV; First stop preferred riders]  |\n",
       "| imputed_new_buses | 4                                                          | 0.0210838592663638                                         | 0.150849150849151                                          | -0.00651366616844423                                       | 0.0486813847011718                                         | 753890                                                     | rider/date/commute [Pre-HOV; Last stop preferred riders]   |\n",
       "| imputed_new_buses:IsRouteSeattle_10_ride | 4                                                          | 0.00766025028206265                                        | 0.684315684315684                                          | -0.020999466676143                                         | 0.0363199672402683                                         | 753890                                                     | rider/date/commute [Pre-HOV; Last stop preferred riders]   |\n",
       "| imputed_new_buses | 5                                                          | 0.0256411475012276                                         | 0                                                          | 0.0128627832501194                                         | 0.0384195117523358                                         | 733928                                                     | rider/date/commute [Pre-HOV; Seattle preferred riders]     |\n",
       "| imputed_new_buses | 6                                                          | 0.0210875463340533                                         | 0.035964035964036                                          | 0.000309723607852603                                       | 0.0418653690602541                                         | 370670                                                     | rider/date/commute [Pre-HOV; Non-Seattle preferred riders] |\n",
       "\n"
      ],
      "text/plain": [
       "                                         model OLS Estimate        \n",
       "imputed_new_buses                        1     0.0235643378914852  \n",
       "imputed_new_buses                        2     0.0202457843501052  \n",
       "imputed_new_buses:IsRouteSeattle_10_ride 2     0.00598164268673898 \n",
       "imputed_new_buses                        3     0.0287743502789941  \n",
       "imputed_new_buses:IsRouteSeattle_10_ride 3     -0.00271030714203348\n",
       "imputed_new_buses                        4     0.0210838592663638  \n",
       "imputed_new_buses:IsRouteSeattle_10_ride 4     0.00766025028206265 \n",
       "imputed_new_buses                        5     0.0256411475012276  \n",
       "imputed_new_buses                        6     0.0210875463340533  \n",
       "                                         BS p-value        CI lower            \n",
       "imputed_new_buses                        0                 0.0109217227329597  \n",
       "imputed_new_buses                        0.108891108891109 -0.00303352246619289\n",
       "imputed_new_buses:IsRouteSeattle_10_ride 0.74025974025974  -0.0195826163881079 \n",
       "imputed_new_buses                        0.150849150849151 -0.00584619735525286\n",
       "imputed_new_buses:IsRouteSeattle_10_ride 0.898101898101898 -0.0393126279437267 \n",
       "imputed_new_buses                        0.150849150849151 -0.00651366616844423\n",
       "imputed_new_buses:IsRouteSeattle_10_ride 0.684315684315684 -0.020999466676143  \n",
       "imputed_new_buses                        0                 0.0128627832501194  \n",
       "imputed_new_buses                        0.035964035964036 0.000309723607852603\n",
       "                                         CI higher          N      \n",
       "imputed_new_buses                        0.0362069530500107 1104348\n",
       "imputed_new_buses                        0.0435250911664033 1104348\n",
       "imputed_new_buses:IsRouteSeattle_10_ride 0.0315459017615859 1104348\n",
       "imputed_new_buses                        0.0633948979132411 471656 \n",
       "imputed_new_buses:IsRouteSeattle_10_ride 0.0338920136596597 471656 \n",
       "imputed_new_buses                        0.0486813847011718 753890 \n",
       "imputed_new_buses:IsRouteSeattle_10_ride 0.0363199672402683 753890 \n",
       "imputed_new_buses                        0.0384195117523358 733928 \n",
       "imputed_new_buses                        0.0418653690602541 370670 \n",
       "                                         granularity                                               \n",
       "imputed_new_buses                        rider/date/commute [Pre-HOV]                              \n",
       "imputed_new_buses                        rider/date/commute [Pre-HOV]                              \n",
       "imputed_new_buses:IsRouteSeattle_10_ride rider/date/commute [Pre-HOV]                              \n",
       "imputed_new_buses                        rider/date/commute [Pre-HOV; First stop preferred riders] \n",
       "imputed_new_buses:IsRouteSeattle_10_ride rider/date/commute [Pre-HOV; First stop preferred riders] \n",
       "imputed_new_buses                        rider/date/commute [Pre-HOV; Last stop preferred riders]  \n",
       "imputed_new_buses:IsRouteSeattle_10_ride rider/date/commute [Pre-HOV; Last stop preferred riders]  \n",
       "imputed_new_buses                        rider/date/commute [Pre-HOV; Seattle preferred riders]    \n",
       "imputed_new_buses                        rider/date/commute [Pre-HOV; Non-Seattle preferred riders]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "\n",
    "rbind( table2_model1_pre_HOV,\n",
    "       table2_model2,\n",
    "       table2_model3_pre_HOV,\n",
    "       table2_model4_pre_HOV,\n",
    "       table2_model5_pre_HOV,\n",
    "       table2_model6_pre_HOV)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Fit the Models for Table 3 "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "in progress\n",
      "Starting at 2020-07-03 23:23:06Starting the base glm (OLS) model...at 0.002\n",
      "Finished the base glm (OLS) model... in 4.118 seconds\n",
      "Starting the summary()...at 4.118\n",
      "\n",
      "===============================================\n",
      "Model  1 :\n",
      "===============================================\n",
      "\n",
      "\n",
      "Coefficients from Linear model (adjust_for effects omitted):\n",
      "    Estimate   Std. Error      t value     Pr(>|t|) \n",
      "1.837058e-02 1.312342e-03 1.399831e+01 1.604787e-44 \n",
      "Finished the summary in 1.729 seconds\n",
      "Starting the wild bootstraps...at 4.192\n",
      "\n",
      " \n",
      " Note: null not imposed (factor variables are present). \n",
      " \n",
      "else... \n",
      "Wild Cluster bootstrapping w/o imposing null... \n",
      "================================================================================\n",
      "Id: job20200704063309\n",
      "chunkSize: 1\n",
      "enableCloudCombine: TRUE\n",
      "errorHandling: stop\n",
      "wait: TRUE\n",
      "autoDeleteJob: TRUE\n",
      "================================================================================\n",
      "Submitting tasks (1001/1001)\n",
      "Submitting merge task. . .\n",
      "Waiting for tasks to complete. . .\n",
      "| Progress: 100.00% (1001/1001) | Running: 0 | Queued: 0 | Completed: 1001 | Failed: 0 |\n",
      "Tasks have completed. Merging results........ Completed.\n",
      "Finished the wild bootstraps...\n",
      "Finished wild bootstraps in 2.926 seconds\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<thead><tr><th></th><th scope=col>model</th><th scope=col>OLS Estimate</th><th scope=col>BS p-value</th><th scope=col>CI lower</th><th scope=col>CI higher</th><th scope=col>N</th><th scope=col>granularity</th></tr></thead>\n",
       "<tbody>\n",
       "\t<tr><th scope=row>post_hov:IsRouteSeattle_10_ride</th><td>1                  </td><td>0.0183705752972965 </td><td>0.00899100899100902</td><td>0.00434138969757729</td><td>0.0323997608970156 </td><td>1792156            </td><td>rider/date/commute </td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "\\begin{tabular}{r|lllllll}\n",
       "  & model & OLS Estimate & BS p-value & CI lower & CI higher & N & granularity\\\\\n",
       "\\hline\n",
       "\tpost\\_hov:IsRouteSeattle\\_10\\_ride & 1                   & 0.0183705752972965  & 0.00899100899100902 & 0.00434138969757729 & 0.0323997608970156  & 1792156             & rider/date/commute \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "| <!--/--> | model | OLS Estimate | BS p-value | CI lower | CI higher | N | granularity |\n",
       "|---|---|---|---|---|---|---|---|\n",
       "| post_hov:IsRouteSeattle_10_ride | 1                   | 0.0183705752972965  | 0.00899100899100902 | 0.00434138969757729 | 0.0323997608970156  | 1792156             | rider/date/commute  |\n",
       "\n"
      ],
      "text/plain": [
       "                                model OLS Estimate       BS p-value         \n",
       "post_hov:IsRouteSeattle_10_ride 1     0.0183705752972965 0.00899100899100902\n",
       "                                CI lower            CI higher          N      \n",
       "post_hov:IsRouteSeattle_10_ride 0.00434138969757729 0.0323997608970156 1792156\n",
       "                                granularity       \n",
       "post_hov:IsRouteSeattle_10_ride rider/date/commute"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "\n",
    "cat(\"in progress\\n\")\n",
    "(table3_model1 = fit_ridership_logit_models(data = commute_ride_data,\n",
    "                        predictors=c(\"post_hov:IsRouteSeattle_10_ride\"),\n",
    "                        adjust_for=c(\"imputed_new_buses + AfternoonId + fDate\",\n",
    "                                        \"f_favorite_route\", \"f_commutes_since_last_ride\"),\n",
    "                        model=1,\n",
    "                        granularity=\"rider/date/commute\"))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 72,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "in progress\n",
      "Starting at 2020-07-04 12:37:09\n",
      "Starting the base glm (OLS) model...at 0.001\n",
      "Finished the base glm (OLS) model... in 4.134 seconds\n",
      "Starting the summary()...at 4.134\n",
      "\n",
      "===============================================\n",
      "Model  2 :\n",
      "===============================================\n",
      "\n",
      "\n",
      "Coefficients from Linear model (adjust_for effects omitted):\n",
      "                                                    Estimate  Std. Error\n",
      "IsRouteSeattle_10_ride:post_hov                  0.009675827 0.002816450\n",
      "is_peak_10_ride                                  0.009662023 0.002073668\n",
      "is_peak_10_ride:IsRouteSeattle_10_ride           0.027895829 0.002505629\n",
      "is_peak_10_ride:post_hov                        -0.024075020 0.003280764\n",
      "is_peak_10_ride:IsRouteSeattle_10_ride:post_hov  0.011941002 0.003997008\n",
      "                                                  t value     Pr(>|t|)\n",
      "IsRouteSeattle_10_ride:post_hov                  3.435469 5.915434e-04\n",
      "is_peak_10_ride                                  4.659387 3.171749e-06\n",
      "is_peak_10_ride:IsRouteSeattle_10_ride          11.133266 8.659872e-29\n",
      "is_peak_10_ride:post_hov                        -7.338235 2.165201e-13\n",
      "is_peak_10_ride:IsRouteSeattle_10_ride:post_hov  2.987485 2.812865e-03\n",
      "Finished the summary in 1.241 seconds\n",
      "Starting the wild bootstraps...at 4.193\n",
      "\n",
      " \n",
      " Note: null not imposed (factor variables are present). \n",
      " \n",
      "else... \n",
      "Wild Cluster bootstrapping w/o imposing null... \n",
      "================================================================================\n",
      "Id: job20200704194622\n",
      "chunkSize: 1\n",
      "enableCloudCombine: TRUE\n",
      "errorHandling: stop\n",
      "wait: TRUE\n",
      "autoDeleteJob: TRUE\n",
      "================================================================================\n",
      "Submitting tasks (1001/1001)\n",
      "Submitting merge task. . .\n",
      "Waiting for tasks to complete. . .\n",
      "| Progress: 100.00% (1001/1001) | Running: 0 | Queued: 0 | Completed: 1001 | Failed: 0 |\n",
      "Tasks have completed. Merging results....... Completed.\n",
      "Finished the wild bootstraps...\n",
      "Finished wild bootstraps in 2.805 seconds\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<thead><tr><th></th><th scope=col>model</th><th scope=col>OLS Estimate</th><th scope=col>BS p-value</th><th scope=col>CI lower</th><th scope=col>CI higher</th><th scope=col>N</th><th scope=col>granularity</th></tr></thead>\n",
       "<tbody>\n",
       "\t<tr><th scope=row>IsRouteSeattle_10_ride:post_hov</th><td>2                   </td><td>0.00967582687881887 </td><td>0.405594405594406   </td><td>-0.0187931699057862 </td><td>0.0381448236634239  </td><td>1792156             </td><td>rider/date/commute  </td></tr>\n",
       "\t<tr><th scope=row>is_peak_10_ride</th><td>2                   </td><td>0.0096620228890113  </td><td>0.194805194805195   </td><td>-0.00596663909776428</td><td>0.0252906848757869  </td><td>1792156             </td><td>rider/date/commute  </td></tr>\n",
       "\t<tr><th scope=row>is_peak_10_ride:IsRouteSeattle_10_ride</th><td>2                   </td><td>0.027895829395243   </td><td>0.00599400599400601 </td><td>0.00793474727358552 </td><td>0.0478569115169005  </td><td>1792156             </td><td>rider/date/commute  </td></tr>\n",
       "\t<tr><th scope=row>is_peak_10_ride:post_hov</th><td>2                   </td><td>-0.024075019612489  </td><td>0.0529470529470529  </td><td>-0.0485569787637584 </td><td>0.000406939538780342</td><td>1792156             </td><td>rider/date/commute  </td></tr>\n",
       "\t<tr><th scope=row>is_peak_10_ride:IsRouteSeattle_10_ride:post_hov</th><td>2                   </td><td>0.011941001630783   </td><td>0.320679320679321   </td><td>-0.0134873753381331 </td><td>0.0373693785996991  </td><td>1792156             </td><td>rider/date/commute  </td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "\\begin{tabular}{r|lllllll}\n",
       "  & model & OLS Estimate & BS p-value & CI lower & CI higher & N & granularity\\\\\n",
       "\\hline\n",
       "\tIsRouteSeattle\\_10\\_ride:post\\_hov & 2                    & 0.00967582687881887  & 0.405594405594406    & -0.0187931699057862  & 0.0381448236634239   & 1792156              & rider/date/commute  \\\\\n",
       "\tis\\_peak\\_10\\_ride & 2                    & 0.0096620228890113   & 0.194805194805195    & -0.00596663909776428 & 0.0252906848757869   & 1792156              & rider/date/commute  \\\\\n",
       "\tis\\_peak\\_10\\_ride:IsRouteSeattle\\_10\\_ride & 2                    & 0.027895829395243    & 0.00599400599400601  & 0.00793474727358552  & 0.0478569115169005   & 1792156              & rider/date/commute  \\\\\n",
       "\tis\\_peak\\_10\\_ride:post\\_hov & 2                    & -0.024075019612489   & 0.0529470529470529   & -0.0485569787637584  & 0.000406939538780342 & 1792156              & rider/date/commute  \\\\\n",
       "\tis\\_peak\\_10\\_ride:IsRouteSeattle\\_10\\_ride:post\\_hov & 2                    & 0.011941001630783    & 0.320679320679321    & -0.0134873753381331  & 0.0373693785996991   & 1792156              & rider/date/commute  \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "| <!--/--> | model | OLS Estimate | BS p-value | CI lower | CI higher | N | granularity |\n",
       "|---|---|---|---|---|---|---|---|\n",
       "| IsRouteSeattle_10_ride:post_hov | 2                    | 0.00967582687881887  | 0.405594405594406    | -0.0187931699057862  | 0.0381448236634239   | 1792156              | rider/date/commute   |\n",
       "| is_peak_10_ride | 2                    | 0.0096620228890113   | 0.194805194805195    | -0.00596663909776428 | 0.0252906848757869   | 1792156              | rider/date/commute   |\n",
       "| is_peak_10_ride:IsRouteSeattle_10_ride | 2                    | 0.027895829395243    | 0.00599400599400601  | 0.00793474727358552  | 0.0478569115169005   | 1792156              | rider/date/commute   |\n",
       "| is_peak_10_ride:post_hov | 2                    | -0.024075019612489   | 0.0529470529470529   | -0.0485569787637584  | 0.000406939538780342 | 1792156              | rider/date/commute   |\n",
       "| is_peak_10_ride:IsRouteSeattle_10_ride:post_hov | 2                    | 0.011941001630783    | 0.320679320679321    | -0.0134873753381331  | 0.0373693785996991   | 1792156              | rider/date/commute   |\n",
       "\n"
      ],
      "text/plain": [
       "                                                model OLS Estimate       \n",
       "IsRouteSeattle_10_ride:post_hov                 2     0.00967582687881887\n",
       "is_peak_10_ride                                 2     0.0096620228890113 \n",
       "is_peak_10_ride:IsRouteSeattle_10_ride          2     0.027895829395243  \n",
       "is_peak_10_ride:post_hov                        2     -0.024075019612489 \n",
       "is_peak_10_ride:IsRouteSeattle_10_ride:post_hov 2     0.011941001630783  \n",
       "                                                BS p-value         \n",
       "IsRouteSeattle_10_ride:post_hov                 0.405594405594406  \n",
       "is_peak_10_ride                                 0.194805194805195  \n",
       "is_peak_10_ride:IsRouteSeattle_10_ride          0.00599400599400601\n",
       "is_peak_10_ride:post_hov                        0.0529470529470529 \n",
       "is_peak_10_ride:IsRouteSeattle_10_ride:post_hov 0.320679320679321  \n",
       "                                                CI lower            \n",
       "IsRouteSeattle_10_ride:post_hov                 -0.0187931699057862 \n",
       "is_peak_10_ride                                 -0.00596663909776428\n",
       "is_peak_10_ride:IsRouteSeattle_10_ride          0.00793474727358552 \n",
       "is_peak_10_ride:post_hov                        -0.0485569787637584 \n",
       "is_peak_10_ride:IsRouteSeattle_10_ride:post_hov -0.0134873753381331 \n",
       "                                                CI higher            N      \n",
       "IsRouteSeattle_10_ride:post_hov                 0.0381448236634239   1792156\n",
       "is_peak_10_ride                                 0.0252906848757869   1792156\n",
       "is_peak_10_ride:IsRouteSeattle_10_ride          0.0478569115169005   1792156\n",
       "is_peak_10_ride:post_hov                        0.000406939538780342 1792156\n",
       "is_peak_10_ride:IsRouteSeattle_10_ride:post_hov 0.0373693785996991   1792156\n",
       "                                                granularity       \n",
       "IsRouteSeattle_10_ride:post_hov                 rider/date/commute\n",
       "is_peak_10_ride                                 rider/date/commute\n",
       "is_peak_10_ride:IsRouteSeattle_10_ride          rider/date/commute\n",
       "is_peak_10_ride:post_hov                        rider/date/commute\n",
       "is_peak_10_ride:IsRouteSeattle_10_ride:post_hov rider/date/commute"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "\n",
    "cat(\"in progress\\n\")\n",
    "(table3_model2 = fit_ridership_logit_models(data = commute_ride_data,\n",
    "                        predictors= c(\"IsRouteSeattle_10_ride:post_hov\",\n",
    "                                        \"is_peak_10_ride\",\n",
    "                                        \"is_peak_10_ride:IsRouteSeattle_10_ride\",\n",
    "                                        \"is_peak_10_ride:post_hov\",\n",
    "                                        \"is_peak_10_ride:IsRouteSeattle_10_ride:post_hov\"\n",
    "                                ),\n",
    "                        model=2,\n",
    "                        adjust_for=c(\"imputed_new_buses\",\"AfternoonId\",\"fDate\",\n",
    "                                        \"f_favorite_route\", \"f_commutes_since_last_ride\"),\n",
    "                        granularity=\"rider/date/commute\"))\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "in progress\n",
      "Starting at 2020-07-04 05:10:35Starting the base glm (OLS) model...at 0.058\n",
      "Finished the base glm (OLS) model... in 1.379 seconds\n",
      "Starting the summary()...at 1.38\n",
      "\n",
      "===============================================\n",
      "Model  3 :\n",
      "===============================================\n",
      "\n",
      "\n",
      "Coefficients from Linear model (adjust_for effects omitted):\n",
      "    Estimate   Std. Error      t value     Pr(>|t|) \n",
      "1.608901e-02 1.906388e-03 8.439526e+00 3.191725e-17 \n",
      "Finished the summary in 0.52 seconds\n",
      "Starting the wild bootstraps...at 1.403\n",
      "\n",
      " \n",
      " Note: null not imposed (factor variables are present). \n",
      " \n",
      "else... \n",
      "Wild Cluster bootstrapping w/o imposing null... \n",
      "================================================================================\n",
      "Id: job20200704121406\n",
      "chunkSize: 1\n",
      "enableCloudCombine: TRUE\n",
      "errorHandling: stop\n",
      "wait: TRUE\n",
      "autoDeleteJob: TRUE\n",
      "================================================================================\n",
      "Submitting tasks (1001/1001)\n",
      "Submitting merge task. . .\n",
      "Waiting for tasks to complete. . .\n",
      "| Progress: 100.00% (1001/1001) | Running: 0 | Queued: 0 | Completed: 1001 | Failed: 0 |\n",
      "Tasks have completed. Merging results...... Completed.\n",
      "Finished the wild bootstraps...\n",
      "Finished wild bootstraps in 1.192 seconds\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<thead><tr><th></th><th scope=col>model</th><th scope=col>OLS Estimate</th><th scope=col>BS p-value</th><th scope=col>CI lower</th><th scope=col>CI higher</th><th scope=col>N</th><th scope=col>granularity</th></tr></thead>\n",
       "<tbody>\n",
       "\t<tr><th scope=row>post_hov:IsRouteSeattle_10_ride</th><td>3                                              </td><td>0.0160890145503846                             </td><td>0.0269730269730269                             </td><td>0.00188284752424718                            </td><td>0.0302951815765219                             </td><td>762048                                         </td><td>rider/date/commute [first stop prefered riders]</td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "\\begin{tabular}{r|lllllll}\n",
       "  & model & OLS Estimate & BS p-value & CI lower & CI higher & N & granularity\\\\\n",
       "\\hline\n",
       "\tpost\\_hov:IsRouteSeattle\\_10\\_ride & 3                                                   & 0.0160890145503846                                  & 0.0269730269730269                                  & 0.00188284752424718                                 & 0.0302951815765219                                  & 762048                                              & rider/date/commute {[}first stop prefered riders{]}\\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "| <!--/--> | model | OLS Estimate | BS p-value | CI lower | CI higher | N | granularity |\n",
       "|---|---|---|---|---|---|---|---|\n",
       "| post_hov:IsRouteSeattle_10_ride | 3                                               | 0.0160890145503846                              | 0.0269730269730269                              | 0.00188284752424718                             | 0.0302951815765219                              | 762048                                          | rider/date/commute [first stop prefered riders] |\n",
       "\n"
      ],
      "text/plain": [
       "                                model OLS Estimate       BS p-value        \n",
       "post_hov:IsRouteSeattle_10_ride 3     0.0160890145503846 0.0269730269730269\n",
       "                                CI lower            CI higher          N     \n",
       "post_hov:IsRouteSeattle_10_ride 0.00188284752424718 0.0302951815765219 762048\n",
       "                                granularity                                    \n",
       "post_hov:IsRouteSeattle_10_ride rider/date/commute [first stop prefered riders]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "\n",
    "cat(\"in progress\\n\")\n",
    "(table3_model3 = fit_ridership_logit_models(data = commute_ride_data[first_stop_10_ride >= 0.5],\n",
    "                        predictors=c(\"post_hov:IsRouteSeattle_10_ride\"),\n",
    "                        adjust_for=c(\"imputed_new_buses\",\n",
    "                                        \"fDate\",\n",
    "                                        \"f_favorite_route\", \"f_commutes_since_last_ride\" ),\n",
    "                        model=3,\n",
    "                        granularity=\"rider/date/commute [first stop prefered riders]\"))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "in progress\n",
      "Starting at 2020-07-04 06:23:30Starting the base glm (OLS) model...at 0.089\n",
      "Finished the base glm (OLS) model... in 2.51 seconds\n",
      "Starting the summary()...at 2.511\n",
      "\n",
      "===============================================\n",
      "Model  4 :\n",
      "===============================================\n",
      "\n",
      "\n",
      "Coefficients from Linear model (adjust_for effects omitted):\n",
      "    Estimate   Std. Error      t value     Pr(>|t|) \n",
      "1.926888e-02 1.549977e-03 1.243172e+01 1.766898e-35 \n",
      "Finished the summary in 0.766 seconds\n",
      "Starting the wild bootstraps...at 2.553\n",
      "\n",
      " \n",
      " Note: null not imposed (factor variables are present). \n",
      " \n",
      "else... \n",
      "Wild Cluster bootstrapping w/o imposing null... \n",
      "================================================================================\n",
      "Id: job20200704132929\n",
      "chunkSize: 1\n",
      "enableCloudCombine: TRUE\n",
      "errorHandling: stop\n",
      "wait: TRUE\n",
      "autoDeleteJob: TRUE\n",
      "================================================================================\n",
      "Submitting tasks (1001/1001)\n",
      "Submitting merge task. . .\n",
      "Waiting for tasks to complete. . .\n",
      "| Progress: 100.00% (1001/1001) | Running: 0 | Queued: 0 | Completed: 1001 | Failed: 0 |\n",
      "Tasks have completed. Merging results.... Completed.\n",
      "Finished the wild bootstraps...\n",
      "Finished wild bootstraps in 1.379 seconds\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<thead><tr><th></th><th scope=col>model</th><th scope=col>OLS Estimate</th><th scope=col>BS p-value</th><th scope=col>CI lower</th><th scope=col>CI higher</th><th scope=col>N</th><th scope=col>granularity</th></tr></thead>\n",
       "<tbody>\n",
       "\t<tr><th scope=row>post_hov:IsRouteSeattle_10_ride</th><td>4                                             </td><td>0.019268875013347                             </td><td>0.00999000999000998                           </td><td>0.00641486577676826                           </td><td>0.0321228842499257                            </td><td>1218882                                       </td><td>rider/date/commute [last stop prefered riders]</td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "\\begin{tabular}{r|lllllll}\n",
       "  & model & OLS Estimate & BS p-value & CI lower & CI higher & N & granularity\\\\\n",
       "\\hline\n",
       "\tpost\\_hov:IsRouteSeattle\\_10\\_ride & 4                                                  & 0.019268875013347                                  & 0.00999000999000998                                & 0.00641486577676826                                & 0.0321228842499257                                 & 1218882                                            & rider/date/commute {[}last stop prefered riders{]}\\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "| <!--/--> | model | OLS Estimate | BS p-value | CI lower | CI higher | N | granularity |\n",
       "|---|---|---|---|---|---|---|---|\n",
       "| post_hov:IsRouteSeattle_10_ride | 4                                              | 0.019268875013347                              | 0.00999000999000998                            | 0.00641486577676826                            | 0.0321228842499257                             | 1218882                                        | rider/date/commute [last stop prefered riders] |\n",
       "\n"
      ],
      "text/plain": [
       "                                model OLS Estimate      BS p-value         \n",
       "post_hov:IsRouteSeattle_10_ride 4     0.019268875013347 0.00999000999000998\n",
       "                                CI lower            CI higher          N      \n",
       "post_hov:IsRouteSeattle_10_ride 0.00641486577676826 0.0321228842499257 1218882\n",
       "                                granularity                                   \n",
       "post_hov:IsRouteSeattle_10_ride rider/date/commute [last stop prefered riders]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "\n",
    "cat(\"in progress\\n\")\n",
    "(table3_model4 = fit_ridership_logit_models(data = commute_ride_data[last_stop_10_ride >= 0.5],\n",
    "                        predictors=c(\"post_hov:IsRouteSeattle_10_ride\"),\n",
    "                        adjust_for=c(\"imputed_new_buses\",\n",
    "                                        \"fDate\",\n",
    "                                        \"f_favorite_route\", \"f_commutes_since_last_ride\"),\n",
    "                        model=4,\n",
    "                        granularity=\"rider/date/commute [last stop prefered riders]\"))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "in progress\n",
      "Starting at 2020-07-04 07:48:46Starting the base glm (OLS) model...at 0.067\n",
      "Finished the base glm (OLS) model... in 20.956 seconds\n",
      "Starting the summary()...at 21.023\n",
      "\n",
      "===============================================\n",
      "Model  5 :\n",
      "===============================================\n",
      "\n",
      "\n",
      "Coefficients from Linear model (adjust_for effects omitted):\n",
      "   Estimate  Std. Error     t value    Pr(>|t|) \n",
      "0.004726404 0.002114847 2.234868068 0.025426335 \n",
      "Finished the summary in 0.516 seconds\n",
      "Starting the wild bootstraps...at 22.29\n",
      "\n",
      " \n",
      " Note: null not imposed (factor variables are present). \n",
      " \n",
      "else... \n",
      "Wild Cluster bootstrapping w/o imposing null... \n",
      "================================================================================\n",
      "Id: job20200704145005\n",
      "chunkSize: 1\n",
      "enableCloudCombine: TRUE\n",
      "errorHandling: stop\n",
      "wait: TRUE\n",
      "autoDeleteJob: TRUE\n",
      "================================================================================\n",
      "Submitting tasks (1001/1001)\n",
      "Submitting merge task. . .\n",
      "Waiting for tasks to complete. . .\n",
      "| Progress: 100.00% (1001/1001) | Running: 0 | Queued: 0 | Completed: 1001 | Failed: 0 |\n",
      "Tasks have completed. Merging results.... Completed.\n",
      "Finished the wild bootstraps...\n",
      "Finished wild bootstraps in 14.45 seconds\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<thead><tr><th></th><th scope=col>model</th><th scope=col>OLS Estimate</th><th scope=col>BS p-value</th><th scope=col>CI lower</th><th scope=col>CI higher</th><th scope=col>N</th><th scope=col>granularity</th></tr></thead>\n",
       "<tbody>\n",
       "\t<tr><th scope=row>post_hov:IsRouteSeattle_10_ride</th><td>5                   </td><td>0.00472640415759942 </td><td>0.188811188811189   </td><td>-0.00246231348744065</td><td>0.0119151218026395  </td><td>679992              </td><td>ride/date/commute   </td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "\\begin{tabular}{r|lllllll}\n",
       "  & model & OLS Estimate & BS p-value & CI lower & CI higher & N & granularity\\\\\n",
       "\\hline\n",
       "\tpost\\_hov:IsRouteSeattle\\_10\\_ride & 5                    & 0.00472640415759942  & 0.188811188811189    & -0.00246231348744065 & 0.0119151218026395   & 679992               & ride/date/commute   \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "| <!--/--> | model | OLS Estimate | BS p-value | CI lower | CI higher | N | granularity |\n",
       "|---|---|---|---|---|---|---|---|\n",
       "| post_hov:IsRouteSeattle_10_ride | 5                    | 0.00472640415759942  | 0.188811188811189    | -0.00246231348744065 | 0.0119151218026395   | 679992               | ride/date/commute    |\n",
       "\n"
      ],
      "text/plain": [
       "                                model OLS Estimate        BS p-value       \n",
       "post_hov:IsRouteSeattle_10_ride 5     0.00472640415759942 0.188811188811189\n",
       "                                CI lower             CI higher          N     \n",
       "post_hov:IsRouteSeattle_10_ride -0.00246231348744065 0.0119151218026395 679992\n",
       "                                granularity      \n",
       "post_hov:IsRouteSeattle_10_ride ride/date/commute"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "\n",
    "cat(\"in progress\\n\")\n",
    "(table3_model5 = fit_ridership_logit_models(data = commute_ride_data[date >= as.Date(\"2016-03-01\") & \n",
    "                                                        date < as.Date(\"2016-07-01\")],\n",
    "                        predictors=c(\"post_hov:IsRouteSeattle_10_ride\"),\n",
    "                        adjust_for=c(\"imputed_new_buses\",\n",
    "                                        \"fDate\",\n",
    "                                        \"f_favorite_route\", \"f_commutes_since_last_ride\" ),\n",
    "                        model=5,\n",
    "                        granularity=\"ride/date/commute\"))\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Table 3 Summary Statistics"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 73,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "2"
      ],
      "text/latex": [
       "2"
      ],
      "text/markdown": [
       "2"
      ],
      "text/plain": [
       "[1] 2"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<thead><tr><th></th><th scope=col>model</th><th scope=col>OLS Estimate</th><th scope=col>BS p-value</th><th scope=col>CI lower</th><th scope=col>CI higher</th><th scope=col>N</th><th scope=col>granularity</th></tr></thead>\n",
       "<tbody>\n",
       "\t<tr><th scope=row>post_hov:IsRouteSeattle_10_ride</th><td>1                                              </td><td>0.0183705752972965                             </td><td>0.00899100899100902                            </td><td>0.00434138969757729                            </td><td>0.0323997608970156                             </td><td>1792156                                        </td><td>rider/date/commute                             </td></tr>\n",
       "\t<tr><th scope=row>IsRouteSeattle_10_ride:post_hov</th><td>2                                              </td><td>0.00967582687881887                            </td><td>0.405594405594406                              </td><td>-0.0187931699057862                            </td><td>0.0381448236634239                             </td><td>1792156                                        </td><td>rider/date/commute                             </td></tr>\n",
       "\t<tr><th scope=row>is_peak_10_ride</th><td>2                                              </td><td>0.0096620228890113                             </td><td>0.194805194805195                              </td><td>-0.00596663909776428                           </td><td>0.0252906848757869                             </td><td>1792156                                        </td><td>rider/date/commute                             </td></tr>\n",
       "\t<tr><th scope=row>is_peak_10_ride:IsRouteSeattle_10_ride</th><td>2                                              </td><td>0.027895829395243                              </td><td>0.00599400599400601                            </td><td>0.00793474727358552                            </td><td>0.0478569115169005                             </td><td>1792156                                        </td><td>rider/date/commute                             </td></tr>\n",
       "\t<tr><th scope=row>is_peak_10_ride:post_hov</th><td>2                                              </td><td>-0.024075019612489                             </td><td>0.0529470529470529                             </td><td>-0.0485569787637584                            </td><td>0.000406939538780342                           </td><td>1792156                                        </td><td>rider/date/commute                             </td></tr>\n",
       "\t<tr><th scope=row>is_peak_10_ride:IsRouteSeattle_10_ride:post_hov</th><td>2                                              </td><td>0.011941001630783                              </td><td>0.320679320679321                              </td><td>-0.0134873753381331                            </td><td>0.0373693785996991                             </td><td>1792156                                        </td><td>rider/date/commute                             </td></tr>\n",
       "\t<tr><th scope=row>post_hov:IsRouteSeattle_10_ride</th><td>3                                              </td><td>0.0160890145503846                             </td><td>0.0269730269730269                             </td><td>0.00188284752424718                            </td><td>0.0302951815765219                             </td><td>762048                                         </td><td>rider/date/commute [first stop prefered riders]</td></tr>\n",
       "\t<tr><th scope=row>post_hov:IsRouteSeattle_10_ride</th><td>4                                              </td><td>0.019268875013347                              </td><td>0.00999000999000998                            </td><td>0.00641486577676826                            </td><td>0.0321228842499257                             </td><td>1218882                                        </td><td>rider/date/commute [last stop prefered riders] </td></tr>\n",
       "\t<tr><th scope=row>post_hov:IsRouteSeattle_10_ride</th><td>5                                              </td><td>0.00472640415759942                            </td><td>0.188811188811189                              </td><td>-0.00246231348744065                           </td><td>0.0119151218026395                             </td><td>679992                                         </td><td>ride/date/commute                              </td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "\\begin{tabular}{r|lllllll}\n",
       "  & model & OLS Estimate & BS p-value & CI lower & CI higher & N & granularity\\\\\n",
       "\\hline\n",
       "\tpost\\_hov:IsRouteSeattle\\_10\\_ride & 1                                               & 0.0183705752972965                              & 0.00899100899100902                             & 0.00434138969757729                             & 0.0323997608970156                              & 1792156                                         & rider/date/commute                             \\\\\n",
       "\tIsRouteSeattle\\_10\\_ride:post\\_hov & 2                                               & 0.00967582687881887                             & 0.405594405594406                               & -0.0187931699057862                             & 0.0381448236634239                              & 1792156                                         & rider/date/commute                             \\\\\n",
       "\tis\\_peak\\_10\\_ride & 2                                               & 0.0096620228890113                              & 0.194805194805195                               & -0.00596663909776428                            & 0.0252906848757869                              & 1792156                                         & rider/date/commute                             \\\\\n",
       "\tis\\_peak\\_10\\_ride:IsRouteSeattle\\_10\\_ride & 2                                               & 0.027895829395243                               & 0.00599400599400601                             & 0.00793474727358552                             & 0.0478569115169005                              & 1792156                                         & rider/date/commute                             \\\\\n",
       "\tis\\_peak\\_10\\_ride:post\\_hov & 2                                               & -0.024075019612489                              & 0.0529470529470529                              & -0.0485569787637584                             & 0.000406939538780342                            & 1792156                                         & rider/date/commute                             \\\\\n",
       "\tis\\_peak\\_10\\_ride:IsRouteSeattle\\_10\\_ride:post\\_hov & 2                                               & 0.011941001630783                               & 0.320679320679321                               & -0.0134873753381331                             & 0.0373693785996991                              & 1792156                                         & rider/date/commute                             \\\\\n",
       "\tpost\\_hov:IsRouteSeattle\\_10\\_ride & 3                                                   & 0.0160890145503846                                  & 0.0269730269730269                                  & 0.00188284752424718                                 & 0.0302951815765219                                  & 762048                                              & rider/date/commute {[}first stop prefered riders{]}\\\\\n",
       "\tpost\\_hov:IsRouteSeattle\\_10\\_ride & 4                                                   & 0.019268875013347                                   & 0.00999000999000998                                 & 0.00641486577676826                                 & 0.0321228842499257                                  & 1218882                                             & rider/date/commute {[}last stop prefered riders{]} \\\\\n",
       "\tpost\\_hov:IsRouteSeattle\\_10\\_ride & 5                                               & 0.00472640415759942                             & 0.188811188811189                               & -0.00246231348744065                            & 0.0119151218026395                              & 679992                                          & ride/date/commute                              \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "| <!--/--> | model | OLS Estimate | BS p-value | CI lower | CI higher | N | granularity |\n",
       "|---|---|---|---|---|---|---|---|\n",
       "| post_hov:IsRouteSeattle_10_ride | 1                                               | 0.0183705752972965                              | 0.00899100899100902                             | 0.00434138969757729                             | 0.0323997608970156                              | 1792156                                         | rider/date/commute                              |\n",
       "| IsRouteSeattle_10_ride:post_hov | 2                                               | 0.00967582687881887                             | 0.405594405594406                               | -0.0187931699057862                             | 0.0381448236634239                              | 1792156                                         | rider/date/commute                              |\n",
       "| is_peak_10_ride | 2                                               | 0.0096620228890113                              | 0.194805194805195                               | -0.00596663909776428                            | 0.0252906848757869                              | 1792156                                         | rider/date/commute                              |\n",
       "| is_peak_10_ride:IsRouteSeattle_10_ride | 2                                               | 0.027895829395243                               | 0.00599400599400601                             | 0.00793474727358552                             | 0.0478569115169005                              | 1792156                                         | rider/date/commute                              |\n",
       "| is_peak_10_ride:post_hov | 2                                               | -0.024075019612489                              | 0.0529470529470529                              | -0.0485569787637584                             | 0.000406939538780342                            | 1792156                                         | rider/date/commute                              |\n",
       "| is_peak_10_ride:IsRouteSeattle_10_ride:post_hov | 2                                               | 0.011941001630783                               | 0.320679320679321                               | -0.0134873753381331                             | 0.0373693785996991                              | 1792156                                         | rider/date/commute                              |\n",
       "| post_hov:IsRouteSeattle_10_ride | 3                                               | 0.0160890145503846                              | 0.0269730269730269                              | 0.00188284752424718                             | 0.0302951815765219                              | 762048                                          | rider/date/commute [first stop prefered riders] |\n",
       "| post_hov:IsRouteSeattle_10_ride | 4                                               | 0.019268875013347                               | 0.00999000999000998                             | 0.00641486577676826                             | 0.0321228842499257                              | 1218882                                         | rider/date/commute [last stop prefered riders]  |\n",
       "| post_hov:IsRouteSeattle_10_ride | 5                                               | 0.00472640415759942                             | 0.188811188811189                               | -0.00246231348744065                            | 0.0119151218026395                              | 679992                                          | ride/date/commute                               |\n",
       "\n"
      ],
      "text/plain": [
       "                                                model OLS Estimate       \n",
       "post_hov:IsRouteSeattle_10_ride                 1     0.0183705752972965 \n",
       "IsRouteSeattle_10_ride:post_hov                 2     0.00967582687881887\n",
       "is_peak_10_ride                                 2     0.0096620228890113 \n",
       "is_peak_10_ride:IsRouteSeattle_10_ride          2     0.027895829395243  \n",
       "is_peak_10_ride:post_hov                        2     -0.024075019612489 \n",
       "is_peak_10_ride:IsRouteSeattle_10_ride:post_hov 2     0.011941001630783  \n",
       "post_hov:IsRouteSeattle_10_ride                 3     0.0160890145503846 \n",
       "post_hov:IsRouteSeattle_10_ride                 4     0.019268875013347  \n",
       "post_hov:IsRouteSeattle_10_ride                 5     0.00472640415759942\n",
       "                                                BS p-value         \n",
       "post_hov:IsRouteSeattle_10_ride                 0.00899100899100902\n",
       "IsRouteSeattle_10_ride:post_hov                 0.405594405594406  \n",
       "is_peak_10_ride                                 0.194805194805195  \n",
       "is_peak_10_ride:IsRouteSeattle_10_ride          0.00599400599400601\n",
       "is_peak_10_ride:post_hov                        0.0529470529470529 \n",
       "is_peak_10_ride:IsRouteSeattle_10_ride:post_hov 0.320679320679321  \n",
       "post_hov:IsRouteSeattle_10_ride                 0.0269730269730269 \n",
       "post_hov:IsRouteSeattle_10_ride                 0.00999000999000998\n",
       "post_hov:IsRouteSeattle_10_ride                 0.188811188811189  \n",
       "                                                CI lower            \n",
       "post_hov:IsRouteSeattle_10_ride                 0.00434138969757729 \n",
       "IsRouteSeattle_10_ride:post_hov                 -0.0187931699057862 \n",
       "is_peak_10_ride                                 -0.00596663909776428\n",
       "is_peak_10_ride:IsRouteSeattle_10_ride          0.00793474727358552 \n",
       "is_peak_10_ride:post_hov                        -0.0485569787637584 \n",
       "is_peak_10_ride:IsRouteSeattle_10_ride:post_hov -0.0134873753381331 \n",
       "post_hov:IsRouteSeattle_10_ride                 0.00188284752424718 \n",
       "post_hov:IsRouteSeattle_10_ride                 0.00641486577676826 \n",
       "post_hov:IsRouteSeattle_10_ride                 -0.00246231348744065\n",
       "                                                CI higher            N      \n",
       "post_hov:IsRouteSeattle_10_ride                 0.0323997608970156   1792156\n",
       "IsRouteSeattle_10_ride:post_hov                 0.0381448236634239   1792156\n",
       "is_peak_10_ride                                 0.0252906848757869   1792156\n",
       "is_peak_10_ride:IsRouteSeattle_10_ride          0.0478569115169005   1792156\n",
       "is_peak_10_ride:post_hov                        0.000406939538780342 1792156\n",
       "is_peak_10_ride:IsRouteSeattle_10_ride:post_hov 0.0373693785996991   1792156\n",
       "post_hov:IsRouteSeattle_10_ride                 0.0302951815765219   762048 \n",
       "post_hov:IsRouteSeattle_10_ride                 0.0321228842499257   1218882\n",
       "post_hov:IsRouteSeattle_10_ride                 0.0119151218026395   679992 \n",
       "                                                granularity                                    \n",
       "post_hov:IsRouteSeattle_10_ride                 rider/date/commute                             \n",
       "IsRouteSeattle_10_ride:post_hov                 rider/date/commute                             \n",
       "is_peak_10_ride                                 rider/date/commute                             \n",
       "is_peak_10_ride:IsRouteSeattle_10_ride          rider/date/commute                             \n",
       "is_peak_10_ride:post_hov                        rider/date/commute                             \n",
       "is_peak_10_ride:IsRouteSeattle_10_ride:post_hov rider/date/commute                             \n",
       "post_hov:IsRouteSeattle_10_ride                 rider/date/commute [first stop prefered riders]\n",
       "post_hov:IsRouteSeattle_10_ride                 rider/date/commute [last stop prefered riders] \n",
       "post_hov:IsRouteSeattle_10_ride                 ride/date/commute                              "
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "1 + 1\n",
    "rbind( table3_model1,\n",
    "       table3_model2,\n",
    "       table3_model3,\n",
    "       table3_model4,\n",
    "       table3_model5)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Fit the Models for Table 4"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "in progress\n",
      "Starting at 2020-07-03 18:34:46Starting the base glm (OLS) model...at 0.038\n",
      "Finished the base glm (OLS) model... in 4.516 seconds\n",
      "Starting the summary()...at 4.554\n",
      "\n",
      "===============================================\n",
      "Model  1 :\n",
      "===============================================\n",
      "\n",
      "\n",
      "Coefficients from Linear model (adjust_for effects omitted):\n",
      "    Estimate   Std. Error      t value     Pr(>|t|) \n",
      "3.005922e-02 5.994914e-03 5.014119e+00 5.336349e-07 \n",
      "Finished the summary in 0.089 seconds\n",
      "Starting the wild bootstraps...at 5.053\n",
      "\n",
      " \n",
      " Note: null not imposed (factor variables are present). \n",
      " \n",
      "else... \n",
      "Wild Cluster bootstrapping w/o imposing null... \n",
      "================================================================================\n",
      "Id: job20200704013502\n",
      "chunkSize: 1\n",
      "enableCloudCombine: TRUE\n",
      "errorHandling: stop\n",
      "wait: TRUE\n",
      "autoDeleteJob: TRUE\n",
      "================================================================================\n",
      "Submitting tasks (1001/1001)\n",
      "Submitting merge task. . .\n",
      "Waiting for tasks to complete. . .\n",
      "| Progress: 100.00% (1001/1001) | Running: 0 | Queued: 0 | Completed: 1001 | Failed: 0 |\n",
      "Tasks have completed. Merging results. Completed.\n",
      "Finished the wild bootstraps...\n",
      "Finished wild bootstraps in 3.412 seconds\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<thead><tr><th></th><th scope=col>model</th><th scope=col>OLS Estimate</th><th scope=col>BS p-value</th><th scope=col>CI lower</th><th scope=col>CI higher</th><th scope=col>N</th><th scope=col>granularity</th></tr></thead>\n",
       "<tbody>\n",
       "\t<tr><th scope=row>imputed_new_buses</th><td>1                                                </td><td>0.0300592160959473                               </td><td>0.391608391608392                                </td><td>-0.0635522955053955                              </td><td>0.12367072769729                                 </td><td>105112                                           </td><td>rider/date/commute [Single Stop Preferred Riders]</td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "\\begin{tabular}{r|lllllll}\n",
       "  & model & OLS Estimate & BS p-value & CI lower & CI higher & N & granularity\\\\\n",
       "\\hline\n",
       "\timputed\\_new\\_buses & 1                                                     & 0.0300592160959473                                    & 0.391608391608392                                     & -0.0635522955053955                                   & 0.12367072769729                                      & 105112                                                & rider/date/commute {[}Single Stop Preferred Riders{]}\\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "| <!--/--> | model | OLS Estimate | BS p-value | CI lower | CI higher | N | granularity |\n",
       "|---|---|---|---|---|---|---|---|\n",
       "| imputed_new_buses | 1                                                 | 0.0300592160959473                                | 0.391608391608392                                 | -0.0635522955053955                               | 0.12367072769729                                  | 105112                                            | rider/date/commute [Single Stop Preferred Riders] |\n",
       "\n"
      ],
      "text/plain": [
       "                  model OLS Estimate       BS p-value       \n",
       "imputed_new_buses 1     0.0300592160959473 0.391608391608392\n",
       "                  CI lower            CI higher        N     \n",
       "imputed_new_buses -0.0635522955053955 0.12367072769729 105112\n",
       "                  granularity                                      \n",
       "imputed_new_buses rider/date/commute [Single Stop Preferred Riders]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "cat(\"in progress\\n\")\n",
    "(T4_M1 = fit_ridership_logit_models(data = commute_ride_data[ (!SR520WBHOV) & (!SR520EBHOV)& (single_stop_10_ride >= 0.5)],\n",
    "                            predictors=c(\"imputed_new_buses\"),\n",
    "                            adjust_for=c(\"fDate\",\n",
    "                                            \"f_favorite_route\", \"f_commutes_since_last_ride\"),\n",
    "                            model=1,\n",
    "                            granularity=\"rider/date/commute [Single Stop Preferred Riders]\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "in progress\n",
      "Starting at 2020-07-03 18:38:16Starting the base glm (OLS) model...at 0.081\n",
      "Finished the base glm (OLS) model... in 1.084 seconds\n",
      "Starting the summary()...at 1.086\n",
      "\n",
      "===============================================\n",
      "Model  2 :\n",
      "===============================================\n",
      "\n",
      "\n",
      "Coefficients from Linear model (adjust_for effects omitted):\n",
      "                                         Estimate  Std. Error   t value\n",
      "imputed_new_buses                     -0.01450295 0.001969591 -7.363432\n",
      "imputed_new_buses:single_stop_10_ride  0.01128578 0.004476482  2.521128\n",
      "                                          Pr(>|t|)\n",
      "imputed_new_buses                     1.793653e-13\n",
      "imputed_new_buses:single_stop_10_ride 1.169808e-02\n",
      "Finished the summary in 0.795 seconds\n",
      "Starting the wild bootstraps...at 1.123\n",
      "\n",
      " \n",
      " Note: null not imposed (factor variables are present). \n",
      " \n",
      "else... \n",
      "Wild Cluster bootstrapping w/o imposing null... \n",
      "================================================================================\n",
      "Id: job20200704014125\n",
      "chunkSize: 1\n",
      "enableCloudCombine: TRUE\n",
      "errorHandling: stop\n",
      "wait: TRUE\n",
      "autoDeleteJob: TRUE\n",
      "================================================================================\n",
      "Submitting tasks (1001/1001)\n",
      "Submitting merge task. . .\n",
      "Waiting for tasks to complete. . .\n",
      "| Progress: 100.00% (1001/1001) | Running: 0 | Queued: 0 | Completed: 1001 | Failed: 0 |\n",
      "Tasks have completed. Merging results.... Completed.\n",
      "Finished the wild bootstraps...\n",
      "Finished wild bootstraps in 37.299 seconds\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<thead><tr><th></th><th scope=col>model</th><th scope=col>OLS Estimate</th><th scope=col>BS p-value</th><th scope=col>CI lower</th><th scope=col>CI higher</th><th scope=col>N</th><th scope=col>granularity</th></tr></thead>\n",
       "<tbody>\n",
       "\t<tr><th scope=row>imputed_new_buses</th><td>2                  </td><td>-0.0145029487227955</td><td>0.0529470529470529 </td><td>-0.0290965299030591</td><td>9.0632457468133e-05</td><td>1104348            </td><td>rider/date/commute </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:single_stop_10_ride</th><td>2                  </td><td>0.0112857838850693 </td><td>0.503496503496504  </td><td>-0.0176850305794505</td><td>0.040256598349589  </td><td>1104348            </td><td>rider/date/commute </td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "\\begin{tabular}{r|lllllll}\n",
       "  & model & OLS Estimate & BS p-value & CI lower & CI higher & N & granularity\\\\\n",
       "\\hline\n",
       "\timputed\\_new\\_buses & 2                   & -0.0145029487227955 & 0.0529470529470529  & -0.0290965299030591 & 9.0632457468133e-05 & 1104348             & rider/date/commute \\\\\n",
       "\timputed\\_new\\_buses:single\\_stop\\_10\\_ride & 2                   & 0.0112857838850693  & 0.503496503496504   & -0.0176850305794505 & 0.040256598349589   & 1104348             & rider/date/commute \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "| <!--/--> | model | OLS Estimate | BS p-value | CI lower | CI higher | N | granularity |\n",
       "|---|---|---|---|---|---|---|---|\n",
       "| imputed_new_buses | 2                   | -0.0145029487227955 | 0.0529470529470529  | -0.0290965299030591 | 9.0632457468133e-05 | 1104348             | rider/date/commute  |\n",
       "| imputed_new_buses:single_stop_10_ride | 2                   | 0.0112857838850693  | 0.503496503496504   | -0.0176850305794505 | 0.040256598349589   | 1104348             | rider/date/commute  |\n",
       "\n"
      ],
      "text/plain": [
       "                                      model OLS Estimate       \n",
       "imputed_new_buses                     2     -0.0145029487227955\n",
       "imputed_new_buses:single_stop_10_ride 2     0.0112857838850693 \n",
       "                                      BS p-value         CI lower           \n",
       "imputed_new_buses                     0.0529470529470529 -0.0290965299030591\n",
       "imputed_new_buses:single_stop_10_ride 0.503496503496504  -0.0176850305794505\n",
       "                                      CI higher           N      \n",
       "imputed_new_buses                     9.0632457468133e-05 1104348\n",
       "imputed_new_buses:single_stop_10_ride 0.040256598349589   1104348\n",
       "                                      granularity       \n",
       "imputed_new_buses                     rider/date/commute\n",
       "imputed_new_buses:single_stop_10_ride rider/date/commute"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "cat(\"in progress\\n\")\n",
    "(T4_M2 = fit_ridership_logit_models(data = commute_ride_data[(!SR520WBHOV) & (!SR520EBHOV)],\n",
    "                            predictors=c(\"imputed_new_buses\",\n",
    "                                            \"imputed_new_buses:single_stop_10_ride\"\n",
    "                                        ),\n",
    "                            adjust_for=c(\"imputed_new_buses + fDate\",\n",
    "                                            \"f_favorite_route\", \"f_commutes_since_last_ride\" ),\n",
    "                            model=2,\n",
    "                            granularity=\"rider/date/commute\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "in progress\n",
      "Starting at 2020-07-03 19:16:40Starting the base glm (OLS) model...at 0.119\n",
      "Finished the base glm (OLS) model... in 1.111 seconds\n",
      "Starting the summary()...at 1.113\n",
      "\n",
      "===============================================\n",
      "Model  3 :\n",
      "===============================================\n",
      "\n",
      "\n",
      "Coefficients from Linear model (adjust_for effects omitted):\n",
      "                                                 Estimate  Std. Error   t value\n",
      "imputed_new_buses                            -0.304451981 0.040272144 -7.559865\n",
      "Is405North_10_ride:I405HOV                    0.009175211 0.005888231  1.558229\n",
      "imputed_new_buses:I405HOV                     0.298253305 0.040055357  7.446028\n",
      "imputed_new_buses:Is405North_10_ride          0.158611463 0.056649424  2.799878\n",
      "imputed_new_buses:Is405North_10_ride:I405HOV -0.193228163 0.056643873 -3.411281\n",
      "                                                 Pr(>|t|)\n",
      "imputed_new_buses                            4.037963e-14\n",
      "Is405North_10_ride:I405HOV                   1.191793e-01\n",
      "imputed_new_buses:I405HOV                    9.626189e-14\n",
      "imputed_new_buses:Is405North_10_ride         5.112285e-03\n",
      "imputed_new_buses:Is405North_10_ride:I405HOV 6.466075e-04\n",
      "Finished the summary in 0.666 seconds\n",
      "Starting the wild bootstraps...at 1.139\n",
      "\n",
      " \n",
      " Note: null not imposed (factor variables are present). \n",
      " \n",
      "else... \n",
      "Wild Cluster bootstrapping w/o imposing null... \n",
      "================================================================================\n",
      "Id: job20200704021954\n",
      "chunkSize: 1\n",
      "enableCloudCombine: TRUE\n",
      "errorHandling: stop\n",
      "wait: TRUE\n",
      "autoDeleteJob: TRUE\n",
      "================================================================================\n",
      "Submitting tasks (1001/1001)\n",
      "Submitting merge task. . .\n",
      "Waiting for tasks to complete. . .\n",
      "| Progress: 100.00% (1001/1001) | Running: 0 | Queued: 0 | Completed: 1001 | Failed: 0 |\n",
      "Tasks have completed. Merging results.... Completed.\n",
      "Finished the wild bootstraps...\n",
      "Finished wild bootstraps in 38.253 seconds\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<thead><tr><th></th><th scope=col>model</th><th scope=col>OLS Estimate</th><th scope=col>BS p-value</th><th scope=col>CI lower</th><th scope=col>CI higher</th><th scope=col>N</th><th scope=col>granularity</th></tr></thead>\n",
       "<tbody>\n",
       "\t<tr><th scope=row>imputed_new_buses</th><td>3                  </td><td>-0.304451981137305 </td><td>0.272727272727273  </td><td>-0.80079335101832  </td><td>0.191889388743711  </td><td>1104348            </td><td>rider/date/commute </td></tr>\n",
       "\t<tr><th scope=row>Is405North_10_ride:I405HOV</th><td>3                  </td><td>0.00917521123487212</td><td>0.025974025974026  </td><td>0.00118053240279478</td><td>0.0171698900669495 </td><td>1104348            </td><td>rider/date/commute </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:I405HOV</th><td>3                  </td><td>0.298253305343265  </td><td>0.286713286713287  </td><td>-0.233500553144602 </td><td>0.830007163831133  </td><td>1104348            </td><td>rider/date/commute </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:Is405North_10_ride</th><td>3                  </td><td>0.158611462667539  </td><td>0.448551448551449  </td><td>-0.309767159684171 </td><td>0.626990085019249  </td><td>1104348            </td><td>rider/date/commute </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:Is405North_10_ride:I405HOV</th><td>3                  </td><td>-0.19322816333251  </td><td>0.385614385614386  </td><td>-0.694590706001701 </td><td>0.308134379336682  </td><td>1104348            </td><td>rider/date/commute </td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "\\begin{tabular}{r|lllllll}\n",
       "  & model & OLS Estimate & BS p-value & CI lower & CI higher & N & granularity\\\\\n",
       "\\hline\n",
       "\timputed\\_new\\_buses & 3                   & -0.304451981137305  & 0.272727272727273   & -0.80079335101832   & 0.191889388743711   & 1104348             & rider/date/commute \\\\\n",
       "\tIs405North\\_10\\_ride:I405HOV & 3                   & 0.00917521123487212 & 0.025974025974026   & 0.00118053240279478 & 0.0171698900669495  & 1104348             & rider/date/commute \\\\\n",
       "\timputed\\_new\\_buses:I405HOV & 3                   & 0.298253305343265   & 0.286713286713287   & -0.233500553144602  & 0.830007163831133   & 1104348             & rider/date/commute \\\\\n",
       "\timputed\\_new\\_buses:Is405North\\_10\\_ride & 3                   & 0.158611462667539   & 0.448551448551449   & -0.309767159684171  & 0.626990085019249   & 1104348             & rider/date/commute \\\\\n",
       "\timputed\\_new\\_buses:Is405North\\_10\\_ride:I405HOV & 3                   & -0.19322816333251   & 0.385614385614386   & -0.694590706001701  & 0.308134379336682   & 1104348             & rider/date/commute \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "| <!--/--> | model | OLS Estimate | BS p-value | CI lower | CI higher | N | granularity |\n",
       "|---|---|---|---|---|---|---|---|\n",
       "| imputed_new_buses | 3                   | -0.304451981137305  | 0.272727272727273   | -0.80079335101832   | 0.191889388743711   | 1104348             | rider/date/commute  |\n",
       "| Is405North_10_ride:I405HOV | 3                   | 0.00917521123487212 | 0.025974025974026   | 0.00118053240279478 | 0.0171698900669495  | 1104348             | rider/date/commute  |\n",
       "| imputed_new_buses:I405HOV | 3                   | 0.298253305343265   | 0.286713286713287   | -0.233500553144602  | 0.830007163831133   | 1104348             | rider/date/commute  |\n",
       "| imputed_new_buses:Is405North_10_ride | 3                   | 0.158611462667539   | 0.448551448551449   | -0.309767159684171  | 0.626990085019249   | 1104348             | rider/date/commute  |\n",
       "| imputed_new_buses:Is405North_10_ride:I405HOV | 3                   | -0.19322816333251   | 0.385614385614386   | -0.694590706001701  | 0.308134379336682   | 1104348             | rider/date/commute  |\n",
       "\n"
      ],
      "text/plain": [
       "                                             model OLS Estimate       \n",
       "imputed_new_buses                            3     -0.304451981137305 \n",
       "Is405North_10_ride:I405HOV                   3     0.00917521123487212\n",
       "imputed_new_buses:I405HOV                    3     0.298253305343265  \n",
       "imputed_new_buses:Is405North_10_ride         3     0.158611462667539  \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV 3     -0.19322816333251  \n",
       "                                             BS p-value       \n",
       "imputed_new_buses                            0.272727272727273\n",
       "Is405North_10_ride:I405HOV                   0.025974025974026\n",
       "imputed_new_buses:I405HOV                    0.286713286713287\n",
       "imputed_new_buses:Is405North_10_ride         0.448551448551449\n",
       "imputed_new_buses:Is405North_10_ride:I405HOV 0.385614385614386\n",
       "                                             CI lower           \n",
       "imputed_new_buses                            -0.80079335101832  \n",
       "Is405North_10_ride:I405HOV                   0.00118053240279478\n",
       "imputed_new_buses:I405HOV                    -0.233500553144602 \n",
       "imputed_new_buses:Is405North_10_ride         -0.309767159684171 \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV -0.694590706001701 \n",
       "                                             CI higher          N      \n",
       "imputed_new_buses                            0.191889388743711  1104348\n",
       "Is405North_10_ride:I405HOV                   0.0171698900669495 1104348\n",
       "imputed_new_buses:I405HOV                    0.830007163831133  1104348\n",
       "imputed_new_buses:Is405North_10_ride         0.626990085019249  1104348\n",
       "imputed_new_buses:Is405North_10_ride:I405HOV 0.308134379336682  1104348\n",
       "                                             granularity       \n",
       "imputed_new_buses                            rider/date/commute\n",
       "Is405North_10_ride:I405HOV                   rider/date/commute\n",
       "imputed_new_buses:I405HOV                    rider/date/commute\n",
       "imputed_new_buses:Is405North_10_ride         rider/date/commute\n",
       "imputed_new_buses:Is405North_10_ride:I405HOV rider/date/commute"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "cat(\"in progress\\n\")\n",
    "(T4_M3 = fit_ridership_logit_models(data = commute_ride_data[(!SR520WBHOV) & (!SR520EBHOV)],\n",
    "                            predictors=c(\n",
    "                                        \"imputed_new_buses\",\n",
    "                                        \"Is405North_10_ride:I405HOV\",\n",
    "                                        \"imputed_new_buses:I405HOV\",\n",
    "                                        \"imputed_new_buses:Is405North_10_ride\",\n",
    "                                        \"imputed_new_buses:Is405North_10_ride:I405HOV\"\n",
    "                                        ),\n",
    "                            adjust_for=c(\"imputed_new_buses + fDate\",\n",
    "                                            \"f_favorite_route\", \"f_commutes_since_last_ride\"),\n",
    "                            model=3,\n",
    "                            granularity=\"rider/date/commute\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "in progress\n",
      "Starting at 2020-07-03 19:56:03Starting the base glm (OLS) model...at 0.104\n",
      "Finished the base glm (OLS) model... in 1.103 seconds\n",
      "Starting the summary()...at 1.104\n",
      "\n",
      "===============================================\n",
      "Model  4 :\n",
      "===============================================\n",
      "\n",
      "\n",
      "Coefficients from Linear model (adjust_for effects omitted):\n",
      "                                                   Estimate  Std. Error\n",
      "imputed_new_buses                              -0.007156001 0.002153852\n",
      "imputed_new_buses:single_stop_10_ride           0.018826753 0.005815690\n",
      "Is405North_10_ride:I405HOV                      0.020821557 0.004656110\n",
      "imputed_new_buses:Is405North_10_ride:I405HOV   -0.036562447 0.003749062\n",
      "single_stop_10_ride:Is405North_10_ride:I405HOV -0.005827346 0.007374187\n",
      "                                                  t value     Pr(>|t|)\n",
      "imputed_new_buses                              -3.3224201 8.924313e-04\n",
      "imputed_new_buses:single_stop_10_ride           3.2372346 1.206977e-03\n",
      "Is405North_10_ride:I405HOV                      4.4718785 7.754318e-06\n",
      "imputed_new_buses:Is405North_10_ride:I405HOV   -9.7524246 1.804911e-22\n",
      "single_stop_10_ride:Is405North_10_ride:I405HOV -0.7902357 4.293903e-01\n",
      "Finished the summary in 0.743 seconds\n",
      "Starting the wild bootstraps...at 1.141\n",
      "\n",
      " \n",
      " Note: null not imposed (factor variables are present). \n",
      " \n",
      "else... \n",
      "Wild Cluster bootstrapping w/o imposing null... \n",
      "================================================================================\n",
      "Id: job20200704025919\n",
      "chunkSize: 1\n",
      "enableCloudCombine: TRUE\n",
      "errorHandling: stop\n",
      "wait: TRUE\n",
      "autoDeleteJob: TRUE\n",
      "================================================================================\n",
      "Submitting tasks (1001/1001)\n",
      "Submitting merge task. . .\n",
      "Waiting for tasks to complete. . .\n",
      "| Progress: 100.00% (1001/1001) | Running: 0 | Queued: 0 | Completed: 1001 | Failed: 0 |\n",
      "Tasks have completed. Merging results..... Completed.\n",
      "Finished the wild bootstraps...\n",
      "Finished wild bootstraps in 37.96 seconds\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<thead><tr><th></th><th scope=col>model</th><th scope=col>OLS Estimate</th><th scope=col>BS p-value</th><th scope=col>CI lower</th><th scope=col>CI higher</th><th scope=col>N</th><th scope=col>granularity</th></tr></thead>\n",
       "<tbody>\n",
       "\t<tr><th scope=row>imputed_new_buses</th><td>4                   </td><td>-0.00715600145820725</td><td>0.298701298701299   </td><td>-0.0205344850012966 </td><td>0.00622248208488206 </td><td>1104348             </td><td>rider/date/commute  </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:single_stop_10_ride</th><td>4                   </td><td>0.0188267527480515  </td><td>0.483516483516483   </td><td>-0.0415369897628453 </td><td>0.0791904952589482  </td><td>1104348             </td><td>rider/date/commute  </td></tr>\n",
       "\t<tr><th scope=row>Is405North_10_ride:I405HOV</th><td>4                   </td><td>0.0208215565157064  </td><td>0                   </td><td>0.0119254777481951  </td><td>0.0297176352832178  </td><td>1104348             </td><td>rider/date/commute  </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:Is405North_10_ride:I405HOV</th><td>4                   </td><td>-0.036562446961334  </td><td>0                   </td><td>-0.0590871903454751 </td><td>-0.0140377035771928 </td><td>1104348             </td><td>rider/date/commute  </td></tr>\n",
       "\t<tr><th scope=row>single_stop_10_ride:Is405North_10_ride:I405HOV</th><td>4                   </td><td>-0.0058273459333407 </td><td>0.798201798201798   </td><td>-0.060756026498851  </td><td>0.0491013346321696  </td><td>1104348             </td><td>rider/date/commute  </td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "\\begin{tabular}{r|lllllll}\n",
       "  & model & OLS Estimate & BS p-value & CI lower & CI higher & N & granularity\\\\\n",
       "\\hline\n",
       "\timputed\\_new\\_buses & 4                    & -0.00715600145820725 & 0.298701298701299    & -0.0205344850012966  & 0.00622248208488206  & 1104348              & rider/date/commute  \\\\\n",
       "\timputed\\_new\\_buses:single\\_stop\\_10\\_ride & 4                    & 0.0188267527480515   & 0.483516483516483    & -0.0415369897628453  & 0.0791904952589482   & 1104348              & rider/date/commute  \\\\\n",
       "\tIs405North\\_10\\_ride:I405HOV & 4                    & 0.0208215565157064   & 0                    & 0.0119254777481951   & 0.0297176352832178   & 1104348              & rider/date/commute  \\\\\n",
       "\timputed\\_new\\_buses:Is405North\\_10\\_ride:I405HOV & 4                    & -0.036562446961334   & 0                    & -0.0590871903454751  & -0.0140377035771928  & 1104348              & rider/date/commute  \\\\\n",
       "\tsingle\\_stop\\_10\\_ride:Is405North\\_10\\_ride:I405HOV & 4                    & -0.0058273459333407  & 0.798201798201798    & -0.060756026498851   & 0.0491013346321696   & 1104348              & rider/date/commute  \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "| <!--/--> | model | OLS Estimate | BS p-value | CI lower | CI higher | N | granularity |\n",
       "|---|---|---|---|---|---|---|---|\n",
       "| imputed_new_buses | 4                    | -0.00715600145820725 | 0.298701298701299    | -0.0205344850012966  | 0.00622248208488206  | 1104348              | rider/date/commute   |\n",
       "| imputed_new_buses:single_stop_10_ride | 4                    | 0.0188267527480515   | 0.483516483516483    | -0.0415369897628453  | 0.0791904952589482   | 1104348              | rider/date/commute   |\n",
       "| Is405North_10_ride:I405HOV | 4                    | 0.0208215565157064   | 0                    | 0.0119254777481951   | 0.0297176352832178   | 1104348              | rider/date/commute   |\n",
       "| imputed_new_buses:Is405North_10_ride:I405HOV | 4                    | -0.036562446961334   | 0                    | -0.0590871903454751  | -0.0140377035771928  | 1104348              | rider/date/commute   |\n",
       "| single_stop_10_ride:Is405North_10_ride:I405HOV | 4                    | -0.0058273459333407  | 0.798201798201798    | -0.060756026498851   | 0.0491013346321696   | 1104348              | rider/date/commute   |\n",
       "\n"
      ],
      "text/plain": [
       "                                               model OLS Estimate        \n",
       "imputed_new_buses                              4     -0.00715600145820725\n",
       "imputed_new_buses:single_stop_10_ride          4     0.0188267527480515  \n",
       "Is405North_10_ride:I405HOV                     4     0.0208215565157064  \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV   4     -0.036562446961334  \n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV 4     -0.0058273459333407 \n",
       "                                               BS p-value       \n",
       "imputed_new_buses                              0.298701298701299\n",
       "imputed_new_buses:single_stop_10_ride          0.483516483516483\n",
       "Is405North_10_ride:I405HOV                     0                \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV   0                \n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV 0.798201798201798\n",
       "                                               CI lower           \n",
       "imputed_new_buses                              -0.0205344850012966\n",
       "imputed_new_buses:single_stop_10_ride          -0.0415369897628453\n",
       "Is405North_10_ride:I405HOV                     0.0119254777481951 \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV   -0.0590871903454751\n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV -0.060756026498851 \n",
       "                                               CI higher           N      \n",
       "imputed_new_buses                              0.00622248208488206 1104348\n",
       "imputed_new_buses:single_stop_10_ride          0.0791904952589482  1104348\n",
       "Is405North_10_ride:I405HOV                     0.0297176352832178  1104348\n",
       "imputed_new_buses:Is405North_10_ride:I405HOV   -0.0140377035771928 1104348\n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV 0.0491013346321696  1104348\n",
       "                                               granularity       \n",
       "imputed_new_buses                              rider/date/commute\n",
       "imputed_new_buses:single_stop_10_ride          rider/date/commute\n",
       "Is405North_10_ride:I405HOV                     rider/date/commute\n",
       "imputed_new_buses:Is405North_10_ride:I405HOV   rider/date/commute\n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV rider/date/commute"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "cat(\"in progress\\n\")\n",
    "(T4_M4 = fit_ridership_logit_models(data = commute_ride_data[(!SR520WBHOV) & (!SR520EBHOV)],\n",
    "                            predictors=c(\n",
    "                                        \"imputed_new_buses\",\n",
    "                                        \"imputed_new_buses:single_stop_10_ride\",\n",
    "                                        \"Is405North_10_ride:I405HOV\",\n",
    "                                        \"imputed_new_buses:Is405North_10_ride:I405HOV\",\n",
    "                                        \"single_stop_10_ride:Is405North_10_ride:I405HOV\"\n",
    "                                        ),\n",
    "                            adjust_for=c(\"imputed_new_buses + fDate\",\n",
    "                                            \"f_favorite_route\", \"f_commutes_since_last_ride\"),\n",
    "                            model=4,\n",
    "                            granularity=\"rider/date/commute\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "in progress\n",
      "Starting at 2020-07-03 20:35:07Starting the base glm (OLS) model...at 0.119\n",
      "Finished the base glm (OLS) model... in 1.197 seconds\n",
      "Starting the summary()...at 1.199\n",
      "\n",
      "===============================================\n",
      "Model  5 :\n",
      "===============================================\n",
      "\n",
      "\n",
      "Coefficients from Linear model (adjust_for effects omitted):\n",
      "                                                                    Estimate\n",
      "imputed_new_buses                                                -0.00834604\n",
      "imputed_new_buses:single_stop_10_ride                             0.03038559\n",
      "Is405North_10_ride:I405HOV                                        0.01406536\n",
      "imputed_new_buses:Is405North_10_ride:I405HOV                     -0.02692634\n",
      "single_stop_10_ride:Is405North_10_ride:I405HOV                    0.03566705\n",
      "imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV -0.06272479\n",
      "                                                                  Std. Error\n",
      "imputed_new_buses                                                0.002172631\n",
      "imputed_new_buses:single_stop_10_ride                            0.006441539\n",
      "Is405North_10_ride:I405HOV                                       0.004929506\n",
      "imputed_new_buses:Is405North_10_ride:I405HOV                     0.004403062\n",
      "single_stop_10_ride:Is405North_10_ride:I405HOV                   0.012379114\n",
      "imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV 0.015030389\n",
      "                                                                   t value\n",
      "imputed_new_buses                                                -3.841443\n",
      "imputed_new_buses:single_stop_10_ride                             4.717132\n",
      "Is405North_10_ride:I405HOV                                        2.853301\n",
      "imputed_new_buses:Is405North_10_ride:I405HOV                     -6.115366\n",
      "single_stop_10_ride:Is405North_10_ride:I405HOV                    2.881228\n",
      "imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV -4.173198\n",
      "                                                                     Pr(>|t|)\n",
      "imputed_new_buses                                                1.223200e-04\n",
      "imputed_new_buses:single_stop_10_ride                            2.392217e-06\n",
      "Is405North_10_ride:I405HOV                                       4.326842e-03\n",
      "imputed_new_buses:Is405North_10_ride:I405HOV                     9.636745e-10\n",
      "single_stop_10_ride:Is405North_10_ride:I405HOV                   3.961365e-03\n",
      "imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV 3.003769e-05\n",
      "Finished the summary in 0.77 seconds\n",
      "Starting the wild bootstraps...at 1.231\n",
      "\n",
      " \n",
      " Note: null not imposed (factor variables are present). \n",
      " \n",
      "else... \n",
      "Wild Cluster bootstrapping w/o imposing null... \n",
      "================================================================================\n",
      "Id: job20200704033837\n",
      "chunkSize: 1\n",
      "enableCloudCombine: TRUE\n",
      "errorHandling: stop\n",
      "wait: TRUE\n",
      "autoDeleteJob: TRUE\n",
      "================================================================================\n",
      "Submitting tasks (1001/1001)\n",
      "Submitting merge task. . .\n",
      "Waiting for tasks to complete. . .\n",
      "| Progress: 100.00% (1001/1001) | Running: 0 | Queued: 0 | Completed: 1001 | Failed: 0 |\n",
      "Tasks have completed. Merging results..... Completed.\n",
      "Finished the wild bootstraps...\n",
      "Finished wild bootstraps in 38.965 seconds\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<thead><tr><th></th><th scope=col>model</th><th scope=col>OLS Estimate</th><th scope=col>BS p-value</th><th scope=col>CI lower</th><th scope=col>CI higher</th><th scope=col>N</th><th scope=col>granularity</th></tr></thead>\n",
       "<tbody>\n",
       "\t<tr><th scope=row>imputed_new_buses</th><td>5                   </td><td>-0.00834603995034945</td><td>0.213786213786214   </td><td>-0.021094497445236  </td><td>0.00440241754453712 </td><td>1104348             </td><td>rider/date/commute  </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:single_stop_10_ride</th><td>5                   </td><td>0.0303855893485927  </td><td>0.505494505494505   </td><td>-0.0543546681661753 </td><td>0.115125846863361   </td><td>1104348             </td><td>rider/date/commute  </td></tr>\n",
       "\t<tr><th scope=row>Is405North_10_ride:I405HOV</th><td>5                   </td><td>0.0140653641704353  </td><td>0.038961038961039   </td><td>0.000875809173373657</td><td>0.0272549191674969  </td><td>1104348             </td><td>rider/date/commute  </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:Is405North_10_ride:I405HOV</th><td>5                   </td><td>-0.0269263381371685 </td><td>0.016983016983017   </td><td>-0.0462480377400942 </td><td>-0.00760463853424289</td><td>1104348             </td><td>rider/date/commute  </td></tr>\n",
       "\t<tr><th scope=row>single_stop_10_ride:Is405North_10_ride:I405HOV</th><td>5                   </td><td>0.0356670496974082  </td><td>0.448551448551449   </td><td>-0.0496381751505229 </td><td>0.120972274545339   </td><td>1104348             </td><td>rider/date/commute  </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV</th><td>5                   </td><td>-0.0627247875411118 </td><td>0.301698301698302   </td><td>-0.233228017762574  </td><td>0.10777844268035    </td><td>1104348             </td><td>rider/date/commute  </td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "\\begin{tabular}{r|lllllll}\n",
       "  & model & OLS Estimate & BS p-value & CI lower & CI higher & N & granularity\\\\\n",
       "\\hline\n",
       "\timputed\\_new\\_buses & 5                    & -0.00834603995034945 & 0.213786213786214    & -0.021094497445236   & 0.00440241754453712  & 1104348              & rider/date/commute  \\\\\n",
       "\timputed\\_new\\_buses:single\\_stop\\_10\\_ride & 5                    & 0.0303855893485927   & 0.505494505494505    & -0.0543546681661753  & 0.115125846863361    & 1104348              & rider/date/commute  \\\\\n",
       "\tIs405North\\_10\\_ride:I405HOV & 5                    & 0.0140653641704353   & 0.038961038961039    & 0.000875809173373657 & 0.0272549191674969   & 1104348              & rider/date/commute  \\\\\n",
       "\timputed\\_new\\_buses:Is405North\\_10\\_ride:I405HOV & 5                    & -0.0269263381371685  & 0.016983016983017    & -0.0462480377400942  & -0.00760463853424289 & 1104348              & rider/date/commute  \\\\\n",
       "\tsingle\\_stop\\_10\\_ride:Is405North\\_10\\_ride:I405HOV & 5                    & 0.0356670496974082   & 0.448551448551449    & -0.0496381751505229  & 0.120972274545339    & 1104348              & rider/date/commute  \\\\\n",
       "\timputed\\_new\\_buses:single\\_stop\\_10\\_ride:Is405North\\_10\\_ride:I405HOV & 5                    & -0.0627247875411118  & 0.301698301698302    & -0.233228017762574   & 0.10777844268035     & 1104348              & rider/date/commute  \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "| <!--/--> | model | OLS Estimate | BS p-value | CI lower | CI higher | N | granularity |\n",
       "|---|---|---|---|---|---|---|---|\n",
       "| imputed_new_buses | 5                    | -0.00834603995034945 | 0.213786213786214    | -0.021094497445236   | 0.00440241754453712  | 1104348              | rider/date/commute   |\n",
       "| imputed_new_buses:single_stop_10_ride | 5                    | 0.0303855893485927   | 0.505494505494505    | -0.0543546681661753  | 0.115125846863361    | 1104348              | rider/date/commute   |\n",
       "| Is405North_10_ride:I405HOV | 5                    | 0.0140653641704353   | 0.038961038961039    | 0.000875809173373657 | 0.0272549191674969   | 1104348              | rider/date/commute   |\n",
       "| imputed_new_buses:Is405North_10_ride:I405HOV | 5                    | -0.0269263381371685  | 0.016983016983017    | -0.0462480377400942  | -0.00760463853424289 | 1104348              | rider/date/commute   |\n",
       "| single_stop_10_ride:Is405North_10_ride:I405HOV | 5                    | 0.0356670496974082   | 0.448551448551449    | -0.0496381751505229  | 0.120972274545339    | 1104348              | rider/date/commute   |\n",
       "| imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV | 5                    | -0.0627247875411118  | 0.301698301698302    | -0.233228017762574   | 0.10777844268035     | 1104348              | rider/date/commute   |\n",
       "\n"
      ],
      "text/plain": [
       "                                                                 model\n",
       "imputed_new_buses                                                5    \n",
       "imputed_new_buses:single_stop_10_ride                            5    \n",
       "Is405North_10_ride:I405HOV                                       5    \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     5    \n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   5    \n",
       "imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV 5    \n",
       "                                                                 OLS Estimate        \n",
       "imputed_new_buses                                                -0.00834603995034945\n",
       "imputed_new_buses:single_stop_10_ride                            0.0303855893485927  \n",
       "Is405North_10_ride:I405HOV                                       0.0140653641704353  \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     -0.0269263381371685 \n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   0.0356670496974082  \n",
       "imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV -0.0627247875411118 \n",
       "                                                                 BS p-value       \n",
       "imputed_new_buses                                                0.213786213786214\n",
       "imputed_new_buses:single_stop_10_ride                            0.505494505494505\n",
       "Is405North_10_ride:I405HOV                                       0.038961038961039\n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     0.016983016983017\n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   0.448551448551449\n",
       "imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV 0.301698301698302\n",
       "                                                                 CI lower            \n",
       "imputed_new_buses                                                -0.021094497445236  \n",
       "imputed_new_buses:single_stop_10_ride                            -0.0543546681661753 \n",
       "Is405North_10_ride:I405HOV                                       0.000875809173373657\n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     -0.0462480377400942 \n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   -0.0496381751505229 \n",
       "imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV -0.233228017762574  \n",
       "                                                                 CI higher           \n",
       "imputed_new_buses                                                0.00440241754453712 \n",
       "imputed_new_buses:single_stop_10_ride                            0.115125846863361   \n",
       "Is405North_10_ride:I405HOV                                       0.0272549191674969  \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     -0.00760463853424289\n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   0.120972274545339   \n",
       "imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV 0.10777844268035    \n",
       "                                                                 N      \n",
       "imputed_new_buses                                                1104348\n",
       "imputed_new_buses:single_stop_10_ride                            1104348\n",
       "Is405North_10_ride:I405HOV                                       1104348\n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     1104348\n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   1104348\n",
       "imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV 1104348\n",
       "                                                                 granularity       \n",
       "imputed_new_buses                                                rider/date/commute\n",
       "imputed_new_buses:single_stop_10_ride                            rider/date/commute\n",
       "Is405North_10_ride:I405HOV                                       rider/date/commute\n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     rider/date/commute\n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   rider/date/commute\n",
       "imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV rider/date/commute"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "cat(\"in progress\\n\")\n",
    "(T4_M5 = fit_ridership_logit_models(data = commute_ride_data[(!SR520WBHOV) & (!SR520EBHOV)],\n",
    "                            predictors=c(\n",
    "                                        \"imputed_new_buses\",\n",
    "                                        \"imputed_new_buses:single_stop_10_ride\",\n",
    "                                        \"Is405North_10_ride:I405HOV\",\n",
    "                                        \"imputed_new_buses:Is405North_10_ride:I405HOV\",\n",
    "                                        \"single_stop_10_ride:Is405North_10_ride:I405HOV\",\n",
    "                                        \"imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV\"\n",
    "                                        ),\n",
    "                            adjust_for=c(\"imputed_new_buses + fDate\",\n",
    "                                            \"f_favorite_route\", \"f_commutes_since_last_ride\"),\n",
    "                            model=5,\n",
    "                            granularity=\"rider/date/commute\"))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Table 4 Summary Statistics"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<thead><tr><th></th><th scope=col>model</th><th scope=col>OLS Estimate</th><th scope=col>BS p-value</th><th scope=col>CI lower</th><th scope=col>CI higher</th><th scope=col>N</th><th scope=col>granularity</th></tr></thead>\n",
       "<tbody>\n",
       "\t<tr><th scope=row>imputed_new_buses</th><td>1                                                </td><td>0.0300592160959473                               </td><td>0.391608391608392                                </td><td>-0.0635522955053955                              </td><td>0.12367072769729                                 </td><td>105112                                           </td><td>rider/date/commute [Single Stop Preferred Riders]</td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses</th><td>2                                                </td><td>-0.0145029487227955                              </td><td>0.0529470529470529                               </td><td>-0.0290965299030591                              </td><td>9.0632457468133e-05                              </td><td>1104348                                          </td><td>rider/date/commute                               </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:single_stop_10_ride</th><td>2                                                </td><td>0.0112857838850693                               </td><td>0.503496503496504                                </td><td>-0.0176850305794505                              </td><td>0.040256598349589                                </td><td>1104348                                          </td><td>rider/date/commute                               </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses</th><td>3                                                </td><td>-0.304451981137305                               </td><td>0.272727272727273                                </td><td>-0.80079335101832                                </td><td>0.191889388743711                                </td><td>1104348                                          </td><td>rider/date/commute                               </td></tr>\n",
       "\t<tr><th scope=row>Is405North_10_ride:I405HOV</th><td>3                                                </td><td>0.00917521123487212                              </td><td>0.025974025974026                                </td><td>0.00118053240279478                              </td><td>0.0171698900669495                               </td><td>1104348                                          </td><td>rider/date/commute                               </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:I405HOV</th><td>3                                                </td><td>0.298253305343265                                </td><td>0.286713286713287                                </td><td>-0.233500553144602                               </td><td>0.830007163831133                                </td><td>1104348                                          </td><td>rider/date/commute                               </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:Is405North_10_ride</th><td>3                                                </td><td>0.158611462667539                                </td><td>0.448551448551449                                </td><td>-0.309767159684171                               </td><td>0.626990085019249                                </td><td>1104348                                          </td><td>rider/date/commute                               </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:Is405North_10_ride:I405HOV</th><td>3                                                </td><td>-0.19322816333251                                </td><td>0.385614385614386                                </td><td>-0.694590706001701                               </td><td>0.308134379336682                                </td><td>1104348                                          </td><td>rider/date/commute                               </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses</th><td>4                                                </td><td>-0.00715600145820725                             </td><td>0.298701298701299                                </td><td>-0.0205344850012966                              </td><td>0.00622248208488206                              </td><td>1104348                                          </td><td>rider/date/commute                               </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:single_stop_10_ride</th><td>4                                                </td><td>0.0188267527480515                               </td><td>0.483516483516483                                </td><td>-0.0415369897628453                              </td><td>0.0791904952589482                               </td><td>1104348                                          </td><td>rider/date/commute                               </td></tr>\n",
       "\t<tr><th scope=row>Is405North_10_ride:I405HOV</th><td>4                                                </td><td>0.0208215565157064                               </td><td>0                                                </td><td>0.0119254777481951                               </td><td>0.0297176352832178                               </td><td>1104348                                          </td><td>rider/date/commute                               </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:Is405North_10_ride:I405HOV</th><td>4                                                </td><td>-0.036562446961334                               </td><td>0                                                </td><td>-0.0590871903454751                              </td><td>-0.0140377035771928                              </td><td>1104348                                          </td><td>rider/date/commute                               </td></tr>\n",
       "\t<tr><th scope=row>single_stop_10_ride:Is405North_10_ride:I405HOV</th><td>4                                                </td><td>-0.0058273459333407                              </td><td>0.798201798201798                                </td><td>-0.060756026498851                               </td><td>0.0491013346321696                               </td><td>1104348                                          </td><td>rider/date/commute                               </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses</th><td>5                                                </td><td>-0.00834603995034945                             </td><td>0.213786213786214                                </td><td>-0.021094497445236                               </td><td>0.00440241754453712                              </td><td>1104348                                          </td><td>rider/date/commute                               </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:single_stop_10_ride</th><td>5                                                </td><td>0.0303855893485927                               </td><td>0.505494505494505                                </td><td>-0.0543546681661753                              </td><td>0.115125846863361                                </td><td>1104348                                          </td><td>rider/date/commute                               </td></tr>\n",
       "\t<tr><th scope=row>Is405North_10_ride:I405HOV</th><td>5                                                </td><td>0.0140653641704353                               </td><td>0.038961038961039                                </td><td>0.000875809173373657                             </td><td>0.0272549191674969                               </td><td>1104348                                          </td><td>rider/date/commute                               </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:Is405North_10_ride:I405HOV</th><td>5                                                </td><td>-0.0269263381371685                              </td><td>0.016983016983017                                </td><td>-0.0462480377400942                              </td><td>-0.00760463853424289                             </td><td>1104348                                          </td><td>rider/date/commute                               </td></tr>\n",
       "\t<tr><th scope=row>single_stop_10_ride:Is405North_10_ride:I405HOV</th><td>5                                                </td><td>0.0356670496974082                               </td><td>0.448551448551449                                </td><td>-0.0496381751505229                              </td><td>0.120972274545339                                </td><td>1104348                                          </td><td>rider/date/commute                               </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV</th><td>5                                                </td><td>-0.0627247875411118                              </td><td>0.301698301698302                                </td><td>-0.233228017762574                               </td><td>0.10777844268035                                 </td><td>1104348                                          </td><td>rider/date/commute                               </td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "\\begin{tabular}{r|lllllll}\n",
       "  & model & OLS Estimate & BS p-value & CI lower & CI higher & N & granularity\\\\\n",
       "\\hline\n",
       "\timputed\\_new\\_buses & 1                                                     & 0.0300592160959473                                    & 0.391608391608392                                     & -0.0635522955053955                                   & 0.12367072769729                                      & 105112                                                & rider/date/commute {[}Single Stop Preferred Riders{]}\\\\\n",
       "\timputed\\_new\\_buses & 2                                                 & -0.0145029487227955                               & 0.0529470529470529                                & -0.0290965299030591                               & 9.0632457468133e-05                               & 1104348                                           & rider/date/commute                               \\\\\n",
       "\timputed\\_new\\_buses:single\\_stop\\_10\\_ride & 2                                                 & 0.0112857838850693                                & 0.503496503496504                                 & -0.0176850305794505                               & 0.040256598349589                                 & 1104348                                           & rider/date/commute                               \\\\\n",
       "\timputed\\_new\\_buses & 3                                                 & -0.304451981137305                                & 0.272727272727273                                 & -0.80079335101832                                 & 0.191889388743711                                 & 1104348                                           & rider/date/commute                               \\\\\n",
       "\tIs405North\\_10\\_ride:I405HOV & 3                                                 & 0.00917521123487212                               & 0.025974025974026                                 & 0.00118053240279478                               & 0.0171698900669495                                & 1104348                                           & rider/date/commute                               \\\\\n",
       "\timputed\\_new\\_buses:I405HOV & 3                                                 & 0.298253305343265                                 & 0.286713286713287                                 & -0.233500553144602                                & 0.830007163831133                                 & 1104348                                           & rider/date/commute                               \\\\\n",
       "\timputed\\_new\\_buses:Is405North\\_10\\_ride & 3                                                 & 0.158611462667539                                 & 0.448551448551449                                 & -0.309767159684171                                & 0.626990085019249                                 & 1104348                                           & rider/date/commute                               \\\\\n",
       "\timputed\\_new\\_buses:Is405North\\_10\\_ride:I405HOV & 3                                                 & -0.19322816333251                                 & 0.385614385614386                                 & -0.694590706001701                                & 0.308134379336682                                 & 1104348                                           & rider/date/commute                               \\\\\n",
       "\timputed\\_new\\_buses & 4                                                 & -0.00715600145820725                              & 0.298701298701299                                 & -0.0205344850012966                               & 0.00622248208488206                               & 1104348                                           & rider/date/commute                               \\\\\n",
       "\timputed\\_new\\_buses:single\\_stop\\_10\\_ride & 4                                                 & 0.0188267527480515                                & 0.483516483516483                                 & -0.0415369897628453                               & 0.0791904952589482                                & 1104348                                           & rider/date/commute                               \\\\\n",
       "\tIs405North\\_10\\_ride:I405HOV & 4                                                 & 0.0208215565157064                                & 0                                                 & 0.0119254777481951                                & 0.0297176352832178                                & 1104348                                           & rider/date/commute                               \\\\\n",
       "\timputed\\_new\\_buses:Is405North\\_10\\_ride:I405HOV & 4                                                 & -0.036562446961334                                & 0                                                 & -0.0590871903454751                               & -0.0140377035771928                               & 1104348                                           & rider/date/commute                               \\\\\n",
       "\tsingle\\_stop\\_10\\_ride:Is405North\\_10\\_ride:I405HOV & 4                                                 & -0.0058273459333407                               & 0.798201798201798                                 & -0.060756026498851                                & 0.0491013346321696                                & 1104348                                           & rider/date/commute                               \\\\\n",
       "\timputed\\_new\\_buses & 5                                                 & -0.00834603995034945                              & 0.213786213786214                                 & -0.021094497445236                                & 0.00440241754453712                               & 1104348                                           & rider/date/commute                               \\\\\n",
       "\timputed\\_new\\_buses:single\\_stop\\_10\\_ride & 5                                                 & 0.0303855893485927                                & 0.505494505494505                                 & -0.0543546681661753                               & 0.115125846863361                                 & 1104348                                           & rider/date/commute                               \\\\\n",
       "\tIs405North\\_10\\_ride:I405HOV & 5                                                 & 0.0140653641704353                                & 0.038961038961039                                 & 0.000875809173373657                              & 0.0272549191674969                                & 1104348                                           & rider/date/commute                               \\\\\n",
       "\timputed\\_new\\_buses:Is405North\\_10\\_ride:I405HOV & 5                                                 & -0.0269263381371685                               & 0.016983016983017                                 & -0.0462480377400942                               & -0.00760463853424289                              & 1104348                                           & rider/date/commute                               \\\\\n",
       "\tsingle\\_stop\\_10\\_ride:Is405North\\_10\\_ride:I405HOV & 5                                                 & 0.0356670496974082                                & 0.448551448551449                                 & -0.0496381751505229                               & 0.120972274545339                                 & 1104348                                           & rider/date/commute                               \\\\\n",
       "\timputed\\_new\\_buses:single\\_stop\\_10\\_ride:Is405North\\_10\\_ride:I405HOV & 5                                                 & -0.0627247875411118                               & 0.301698301698302                                 & -0.233228017762574                                & 0.10777844268035                                  & 1104348                                           & rider/date/commute                               \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "| <!--/--> | model | OLS Estimate | BS p-value | CI lower | CI higher | N | granularity |\n",
       "|---|---|---|---|---|---|---|---|\n",
       "| imputed_new_buses | 1                                                 | 0.0300592160959473                                | 0.391608391608392                                 | -0.0635522955053955                               | 0.12367072769729                                  | 105112                                            | rider/date/commute [Single Stop Preferred Riders] |\n",
       "| imputed_new_buses | 2                                                 | -0.0145029487227955                               | 0.0529470529470529                                | -0.0290965299030591                               | 9.0632457468133e-05                               | 1104348                                           | rider/date/commute                                |\n",
       "| imputed_new_buses:single_stop_10_ride | 2                                                 | 0.0112857838850693                                | 0.503496503496504                                 | -0.0176850305794505                               | 0.040256598349589                                 | 1104348                                           | rider/date/commute                                |\n",
       "| imputed_new_buses | 3                                                 | -0.304451981137305                                | 0.272727272727273                                 | -0.80079335101832                                 | 0.191889388743711                                 | 1104348                                           | rider/date/commute                                |\n",
       "| Is405North_10_ride:I405HOV | 3                                                 | 0.00917521123487212                               | 0.025974025974026                                 | 0.00118053240279478                               | 0.0171698900669495                                | 1104348                                           | rider/date/commute                                |\n",
       "| imputed_new_buses:I405HOV | 3                                                 | 0.298253305343265                                 | 0.286713286713287                                 | -0.233500553144602                                | 0.830007163831133                                 | 1104348                                           | rider/date/commute                                |\n",
       "| imputed_new_buses:Is405North_10_ride | 3                                                 | 0.158611462667539                                 | 0.448551448551449                                 | -0.309767159684171                                | 0.626990085019249                                 | 1104348                                           | rider/date/commute                                |\n",
       "| imputed_new_buses:Is405North_10_ride:I405HOV | 3                                                 | -0.19322816333251                                 | 0.385614385614386                                 | -0.694590706001701                                | 0.308134379336682                                 | 1104348                                           | rider/date/commute                                |\n",
       "| imputed_new_buses | 4                                                 | -0.00715600145820725                              | 0.298701298701299                                 | -0.0205344850012966                               | 0.00622248208488206                               | 1104348                                           | rider/date/commute                                |\n",
       "| imputed_new_buses:single_stop_10_ride | 4                                                 | 0.0188267527480515                                | 0.483516483516483                                 | -0.0415369897628453                               | 0.0791904952589482                                | 1104348                                           | rider/date/commute                                |\n",
       "| Is405North_10_ride:I405HOV | 4                                                 | 0.0208215565157064                                | 0                                                 | 0.0119254777481951                                | 0.0297176352832178                                | 1104348                                           | rider/date/commute                                |\n",
       "| imputed_new_buses:Is405North_10_ride:I405HOV | 4                                                 | -0.036562446961334                                | 0                                                 | -0.0590871903454751                               | -0.0140377035771928                               | 1104348                                           | rider/date/commute                                |\n",
       "| single_stop_10_ride:Is405North_10_ride:I405HOV | 4                                                 | -0.0058273459333407                               | 0.798201798201798                                 | -0.060756026498851                                | 0.0491013346321696                                | 1104348                                           | rider/date/commute                                |\n",
       "| imputed_new_buses | 5                                                 | -0.00834603995034945                              | 0.213786213786214                                 | -0.021094497445236                                | 0.00440241754453712                               | 1104348                                           | rider/date/commute                                |\n",
       "| imputed_new_buses:single_stop_10_ride | 5                                                 | 0.0303855893485927                                | 0.505494505494505                                 | -0.0543546681661753                               | 0.115125846863361                                 | 1104348                                           | rider/date/commute                                |\n",
       "| Is405North_10_ride:I405HOV | 5                                                 | 0.0140653641704353                                | 0.038961038961039                                 | 0.000875809173373657                              | 0.0272549191674969                                | 1104348                                           | rider/date/commute                                |\n",
       "| imputed_new_buses:Is405North_10_ride:I405HOV | 5                                                 | -0.0269263381371685                               | 0.016983016983017                                 | -0.0462480377400942                               | -0.00760463853424289                              | 1104348                                           | rider/date/commute                                |\n",
       "| single_stop_10_ride:Is405North_10_ride:I405HOV | 5                                                 | 0.0356670496974082                                | 0.448551448551449                                 | -0.0496381751505229                               | 0.120972274545339                                 | 1104348                                           | rider/date/commute                                |\n",
       "| imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV | 5                                                 | -0.0627247875411118                               | 0.301698301698302                                 | -0.233228017762574                                | 0.10777844268035                                  | 1104348                                           | rider/date/commute                                |\n",
       "\n"
      ],
      "text/plain": [
       "                                                                 model\n",
       "imputed_new_buses                                                1    \n",
       "imputed_new_buses                                                2    \n",
       "imputed_new_buses:single_stop_10_ride                            2    \n",
       "imputed_new_buses                                                3    \n",
       "Is405North_10_ride:I405HOV                                       3    \n",
       "imputed_new_buses:I405HOV                                        3    \n",
       "imputed_new_buses:Is405North_10_ride                             3    \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     3    \n",
       "imputed_new_buses                                                4    \n",
       "imputed_new_buses:single_stop_10_ride                            4    \n",
       "Is405North_10_ride:I405HOV                                       4    \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     4    \n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   4    \n",
       "imputed_new_buses                                                5    \n",
       "imputed_new_buses:single_stop_10_ride                            5    \n",
       "Is405North_10_ride:I405HOV                                       5    \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     5    \n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   5    \n",
       "imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV 5    \n",
       "                                                                 OLS Estimate        \n",
       "imputed_new_buses                                                0.0300592160959473  \n",
       "imputed_new_buses                                                -0.0145029487227955 \n",
       "imputed_new_buses:single_stop_10_ride                            0.0112857838850693  \n",
       "imputed_new_buses                                                -0.304451981137305  \n",
       "Is405North_10_ride:I405HOV                                       0.00917521123487212 \n",
       "imputed_new_buses:I405HOV                                        0.298253305343265   \n",
       "imputed_new_buses:Is405North_10_ride                             0.158611462667539   \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     -0.19322816333251   \n",
       "imputed_new_buses                                                -0.00715600145820725\n",
       "imputed_new_buses:single_stop_10_ride                            0.0188267527480515  \n",
       "Is405North_10_ride:I405HOV                                       0.0208215565157064  \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     -0.036562446961334  \n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   -0.0058273459333407 \n",
       "imputed_new_buses                                                -0.00834603995034945\n",
       "imputed_new_buses:single_stop_10_ride                            0.0303855893485927  \n",
       "Is405North_10_ride:I405HOV                                       0.0140653641704353  \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     -0.0269263381371685 \n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   0.0356670496974082  \n",
       "imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV -0.0627247875411118 \n",
       "                                                                 BS p-value        \n",
       "imputed_new_buses                                                0.391608391608392 \n",
       "imputed_new_buses                                                0.0529470529470529\n",
       "imputed_new_buses:single_stop_10_ride                            0.503496503496504 \n",
       "imputed_new_buses                                                0.272727272727273 \n",
       "Is405North_10_ride:I405HOV                                       0.025974025974026 \n",
       "imputed_new_buses:I405HOV                                        0.286713286713287 \n",
       "imputed_new_buses:Is405North_10_ride                             0.448551448551449 \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     0.385614385614386 \n",
       "imputed_new_buses                                                0.298701298701299 \n",
       "imputed_new_buses:single_stop_10_ride                            0.483516483516483 \n",
       "Is405North_10_ride:I405HOV                                       0                 \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     0                 \n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   0.798201798201798 \n",
       "imputed_new_buses                                                0.213786213786214 \n",
       "imputed_new_buses:single_stop_10_ride                            0.505494505494505 \n",
       "Is405North_10_ride:I405HOV                                       0.038961038961039 \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     0.016983016983017 \n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   0.448551448551449 \n",
       "imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV 0.301698301698302 \n",
       "                                                                 CI lower            \n",
       "imputed_new_buses                                                -0.0635522955053955 \n",
       "imputed_new_buses                                                -0.0290965299030591 \n",
       "imputed_new_buses:single_stop_10_ride                            -0.0176850305794505 \n",
       "imputed_new_buses                                                -0.80079335101832   \n",
       "Is405North_10_ride:I405HOV                                       0.00118053240279478 \n",
       "imputed_new_buses:I405HOV                                        -0.233500553144602  \n",
       "imputed_new_buses:Is405North_10_ride                             -0.309767159684171  \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     -0.694590706001701  \n",
       "imputed_new_buses                                                -0.0205344850012966 \n",
       "imputed_new_buses:single_stop_10_ride                            -0.0415369897628453 \n",
       "Is405North_10_ride:I405HOV                                       0.0119254777481951  \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     -0.0590871903454751 \n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   -0.060756026498851  \n",
       "imputed_new_buses                                                -0.021094497445236  \n",
       "imputed_new_buses:single_stop_10_ride                            -0.0543546681661753 \n",
       "Is405North_10_ride:I405HOV                                       0.000875809173373657\n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     -0.0462480377400942 \n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   -0.0496381751505229 \n",
       "imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV -0.233228017762574  \n",
       "                                                                 CI higher           \n",
       "imputed_new_buses                                                0.12367072769729    \n",
       "imputed_new_buses                                                9.0632457468133e-05 \n",
       "imputed_new_buses:single_stop_10_ride                            0.040256598349589   \n",
       "imputed_new_buses                                                0.191889388743711   \n",
       "Is405North_10_ride:I405HOV                                       0.0171698900669495  \n",
       "imputed_new_buses:I405HOV                                        0.830007163831133   \n",
       "imputed_new_buses:Is405North_10_ride                             0.626990085019249   \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     0.308134379336682   \n",
       "imputed_new_buses                                                0.00622248208488206 \n",
       "imputed_new_buses:single_stop_10_ride                            0.0791904952589482  \n",
       "Is405North_10_ride:I405HOV                                       0.0297176352832178  \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     -0.0140377035771928 \n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   0.0491013346321696  \n",
       "imputed_new_buses                                                0.00440241754453712 \n",
       "imputed_new_buses:single_stop_10_ride                            0.115125846863361   \n",
       "Is405North_10_ride:I405HOV                                       0.0272549191674969  \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     -0.00760463853424289\n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   0.120972274545339   \n",
       "imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV 0.10777844268035    \n",
       "                                                                 N      \n",
       "imputed_new_buses                                                105112 \n",
       "imputed_new_buses                                                1104348\n",
       "imputed_new_buses:single_stop_10_ride                            1104348\n",
       "imputed_new_buses                                                1104348\n",
       "Is405North_10_ride:I405HOV                                       1104348\n",
       "imputed_new_buses:I405HOV                                        1104348\n",
       "imputed_new_buses:Is405North_10_ride                             1104348\n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     1104348\n",
       "imputed_new_buses                                                1104348\n",
       "imputed_new_buses:single_stop_10_ride                            1104348\n",
       "Is405North_10_ride:I405HOV                                       1104348\n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     1104348\n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   1104348\n",
       "imputed_new_buses                                                1104348\n",
       "imputed_new_buses:single_stop_10_ride                            1104348\n",
       "Is405North_10_ride:I405HOV                                       1104348\n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     1104348\n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   1104348\n",
       "imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV 1104348\n",
       "                                                                 granularity                                      \n",
       "imputed_new_buses                                                rider/date/commute [Single Stop Preferred Riders]\n",
       "imputed_new_buses                                                rider/date/commute                               \n",
       "imputed_new_buses:single_stop_10_ride                            rider/date/commute                               \n",
       "imputed_new_buses                                                rider/date/commute                               \n",
       "Is405North_10_ride:I405HOV                                       rider/date/commute                               \n",
       "imputed_new_buses:I405HOV                                        rider/date/commute                               \n",
       "imputed_new_buses:Is405North_10_ride                             rider/date/commute                               \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     rider/date/commute                               \n",
       "imputed_new_buses                                                rider/date/commute                               \n",
       "imputed_new_buses:single_stop_10_ride                            rider/date/commute                               \n",
       "Is405North_10_ride:I405HOV                                       rider/date/commute                               \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     rider/date/commute                               \n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   rider/date/commute                               \n",
       "imputed_new_buses                                                rider/date/commute                               \n",
       "imputed_new_buses:single_stop_10_ride                            rider/date/commute                               \n",
       "Is405North_10_ride:I405HOV                                       rider/date/commute                               \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     rider/date/commute                               \n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   rider/date/commute                               \n",
       "imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV rider/date/commute                               "
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "(TABLE_4 <- rbind(T4_M1,T4_M2,T4_M3,T4_M4,T4_M5))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "2"
      ],
      "text/latex": [
       "2"
      ],
      "text/markdown": [
       "2"
      ],
      "text/plain": [
       "[1] 2"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "1 + 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "R",
   "language": "R",
   "name": "ir"
  },
  "language_info": {
   "codemirror_mode": "r",
   "file_extension": ".r",
   "mimetype": "text/x-r-source",
   "name": "R",
   "pygments_lexer": "r",
   "version": "3.5.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
